diff options
-rw-r--r-- | lib/puppet/application.rb | 21 | ||||
-rwxr-xr-x | spec/unit/application.rb | 17 |
2 files changed, 26 insertions, 12 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index e7240f773..2882c8191 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -210,11 +210,11 @@ class Puppet::Application # This is the main application entry point def run - run_preinit - parse_options - Puppet.settings.parse if should_parse_config? - run_setup - run_command + exit_on_fail("initialize") { run_preinit } + exit_on_fail("parse options") { parse_options } + exit_on_fail("parse configuration file") { Puppet.settings.parse } if should_parse_config? + exit_on_fail("prepare for execution") { run_setup } + exit_on_fail("run") { run_command } end def main @@ -299,4 +299,15 @@ class Puppet::Application end end + private + + def exit_on_fail(message, code = 1) + begin + yield + rescue RuntimeError, NotImplementedError => detail + puts detail.backtrace if Puppet[:trace] + $stderr.puts "Could not %s: %s" % [message, detail] + exit(code) + end + end end diff --git a/spec/unit/application.rb b/spec/unit/application.rb index 5c3df0999..c087373ac 100755 --- a/spec/unit/application.rb +++ b/spec/unit/application.rb @@ -261,22 +261,25 @@ describe Puppet::Application do @app.run end - it "should raise an error if no command can be called" do - lambda { @app.run }.should raise_error(NotImplementedError) + it "should warn and exit if no command can be called" do + $stderr.expects(:puts) + @app.expects(:exit).with(1) + @app.run end it "should raise an error if dispatch returns no command" do @app.stubs(:get_command).returns(nil) - - lambda { @app.run }.should raise_error(NotImplementedError) + $stderr.expects(:puts) + @app.expects(:exit).with(1) + @app.run end it "should raise an error if dispatch returns an invalid command" do @app.stubs(:get_command).returns(:this_function_doesnt_exist) - - lambda { @app.run }.should raise_error(NotImplementedError) + $stderr.expects(:puts) + @app.expects(:exit).with(1) + @app.run end - end describe "when metaprogramming" do |