summaryrefslogtreecommitdiffstats
path: root/lib/puppet/application
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-22 11:53:30 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-22 15:39:06 -0700
commitf77304b703cbaaf5b46b974a0c80b73cece4a2aa (patch)
treedca46a71880832bbf91c6ad99c5264681546ae68 /lib/puppet/application
parent435c826ead5c81c3eb7c47efe9c52e2e77c14666 (diff)
downloadpuppet-f77304b703cbaaf5b46b974a0c80b73cece4a2aa.tar.gz
puppet-f77304b703cbaaf5b46b974a0c80b73cece4a2aa.tar.xz
puppet-f77304b703cbaaf5b46b974a0c80b73cece4a2aa.zip
(#7157) Return a non-zero exit code on face failure.
When a face or action fails we should exit non-zero on the CLI to signal this to our caller. "Fails" is defined as "raises an exception"; we don't treat any return value as a significant failure. Reviewed-By: Jesse Wolf <jesse@puppetlabs.com>
Diffstat (limited to 'lib/puppet/application')
-rw-r--r--lib/puppet/application/face_base.rb26
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb
index 7bebd18bb..257d51f75 100644
--- a/lib/puppet/application/face_base.rb
+++ b/lib/puppet/application/face_base.rb
@@ -27,13 +27,6 @@ class Puppet::Application::FaceBase < Puppet::Application
attr_accessor :face, :action, :type, :arguments, :render_as
- attr_writer :exit_code
-
- # This allows you to set the exit code if you don't want to just exit
- # immediately but you need to indicate a failure.
- def exit_code
- @exit_code || 0
- end
def render(result)
format = render_as || action.render_as || :for_humans
@@ -198,19 +191,28 @@ class Puppet::Application::FaceBase < Puppet::Application
def main
+ status = false
+
# Call the method associated with the provided action (e.g., 'find').
if @action
- result = @face.send(@action.name, *arguments)
- puts render(result) unless result.nil?
+ begin
+ result = @face.send(@action.name, *arguments)
+ puts render(result) unless result.nil?
+ status = true
+ rescue Exception => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err detail.to_s
+ end
else
if arguments.first.is_a? Hash
- puts "#{@face} does not have a default action"
+ puts "#{face} does not have a default action"
else
- puts "#{@face} does not respond to action #{arguments.first}"
+ puts "#{face} does not respond to action #{arguments.first}"
end
puts Puppet::Face[:help, :current].help(@face.name, *arguments)
end
- exit(exit_code)
+
+ exit status
end
end