diff options
author | Ryota Arai <ryota.arai@gmail.com> | 2013-10-31 08:58:23 +0900 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-11-26 07:31:19 -0800 |
commit | 57ebf9cbbb80573bde2cb8598733fade07190578 (patch) | |
tree | 0fae70ecb57bf4d721a8068e068f47058489ef2c | |
parent | b3073d986378357b662c15ea35b1eb8cc520fafd (diff) | |
download | chef-57ebf9cbbb80573bde2cb8598733fade07190578.tar.gz |
Refactor handle_command_failures method.
-rw-r--r-- | lib/chef/mixin/command.rb | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/lib/chef/mixin/command.rb b/lib/chef/mixin/command.rb index fb75980f8f..c92315e718 100644 --- a/lib/chef/mixin/command.rb +++ b/lib/chef/mixin/command.rb @@ -144,19 +144,18 @@ class Chef end def handle_command_failures(status, command_output, opts={}) - unless opts[:ignore_failure] - opts[:returns] ||= 0 - unless Array(opts[:returns]).include?(status.exitstatus) - # if the log level is not debug, through output of command when we fail - output = "" - if Chef::Log.level == :debug || opts[:output_on_failure] - output << "\n---- Begin output of #{opts[:command]} ----\n" - output << command_output.to_s - output << "\n---- End output of #{opts[:command]} ----\n" - end - raise Chef::Exceptions::Exec, "#{opts[:command]} returned #{status.exitstatus}, expected #{opts[:returns]}#{output}" - end + return if opts[:ignore_failure] + opts[:returns] ||= 0 + return if Array(opts[:returns]).include?(status.exitstatus) + + # if the log level is not debug, through output of command when we fail + output = "" + if Chef::Log.level == :debug || opts[:output_on_failure] + output << "\n---- Begin output of #{opts[:command]} ----\n" + output << command_output.to_s + output << "\n---- End output of #{opts[:command]} ----\n" end + raise Chef::Exceptions::Exec, "#{opts[:command]} returned #{status.exitstatus}, expected #{opts[:returns]}#{output}" end # Call #run_command but set LC_ALL to the system's current environment so it doesn't get changed to C. |