Skip to content

Commit

Permalink
Fix error handling when puppet is not installed
Browse files Browse the repository at this point in the history
Bug introduced by 3b69495. The error message
generated in response to an error in running 'puppet --version' itself
generated a new error by referencing a 'status' method that does not exist.
  • Loading branch information
Phil Frost committed Apr 8, 2014
1 parent 3b69495 commit 3e1fe89
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
32 changes: 17 additions & 15 deletions lib/librarian/puppet.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
require 'librarian'
require 'fileutils'

out = nil
begin
out = Librarian::Posix.run!(%W{puppet --version})
rescue Librarian::Posix::CommandFailure => error

$stderr.puts <<-EOF
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc).
puppet --version returned #{status.exitstatus}
#{error.message unless error.message.nil?}
EOF
exit 1
end

PUPPET_VERSION=out.split(' ').first.strip

require 'librarian/puppet/extension'
require 'librarian/puppet/version'

require 'librarian/action/install'

module Librarian
module Puppet
def puppet_version
out = nil
begin
out = Librarian::Posix.run!(%W{puppet --version})
rescue Librarian::Posix::CommandFailure => error

$stderr.puts <<-EOF
Unable to load puppet. Please install it using native packages for your platform (eg .deb, .rpm, .dmg, etc).
puppet --version returned #{error.status}
#{error.message unless error.message.nil?}
EOF
exit 1
end
out.split(' ').first.strip
end
end
end

PUPPET_VERSION=Librarian::Puppet::puppet_version
14 changes: 14 additions & 0 deletions spec/librarian_puppet_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe Librarian::Puppet do
it 'exits with error if puppet is not installed' do
error = Librarian::Posix::CommandFailure.new 'puppet not installed'
error.status = 42

expect(Librarian::Posix).to receive(:run!).and_raise(error)
expect($stderr).to receive(:puts) do |message|
expect(message).to match /42/
expect(message).to match /puppet not installed/
end

expect { Librarian::Puppet::puppet_version }.to raise_error(SystemExit)
end
end

0 comments on commit 3e1fe89

Please sign in to comment.