+1 On 24/07/09 4:13, Luke Kanies wrote: > This protects the user from seeing stack traces in normal situations. > It makes sense here because this is explicitly for user interactions. > > Signed-off-by: Luke Kanies <[email protected]> > --- > lib/puppet/application.rb | 21 ++++++++++++++++----- > 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 e7240f7..2882c81 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 5c3df09..c087373 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
-- Brice Figureau My Blog: http://www.masterzen.fr/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
