diff options
author | Chris Armstrong <chris.armstrong@socrata.com> | 2013-09-24 14:46:47 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2014-01-21 17:15:22 -0800 |
commit | 6baa0861a364adbac507a447b6cb3cbad4a160b1 (patch) | |
tree | 2a39182337512e17bd5651d0e277f18bc399d02d /lib/mixlib/shellout.rb | |
parent | fa0a9c82b50bf941f34b2480f80fb5c88fd241db (diff) | |
download | mixlib-shellout-6baa0861a364adbac507a447b6cb3cbad4a160b1.tar.gz |
Adds error? method to check whether the process exited successfully. This allows the user to use custom error-handling logic. error! now uses error? internally.
Diffstat (limited to 'lib/mixlib/shellout.rb')
-rw-r--r-- | lib/mixlib/shellout.rb | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/mixlib/shellout.rb b/lib/mixlib/shellout.rb index 66faa40..e4e0435 100644 --- a/lib/mixlib/shellout.rb +++ b/lib/mixlib/shellout.rb @@ -49,8 +49,8 @@ module Mixlib # Working directory for the subprocess. Normally set via options to new attr_accessor :cwd - # An Array of acceptable exit codes. #error! uses this list to determine if - # the command was successful. Normally set via options to new + # An Array of acceptable exit codes. #error? (and #error!) use this list + # to determine if the command was successful. Normally set via options to new attr_accessor :valid_exit_codes # When live_stream is set, stdout of the subprocess will be copied to it as @@ -227,17 +227,21 @@ module Mixlib super end - # Checks the +exitstatus+ against the set of +valid_exit_codes+. If - # +exitstatus+ is not in the list of +valid_exit_codes+, calls +invalid!+, - # which raises an Exception. + # Checks the +exitstatus+ against the set of +valid_exit_codes+. + # === Returns + # +true+ if +exitstatus+ is not in the list of +valid_exit_codes+, false + # otherwise. + def error? + !Array(valid_exit_codes).include?(exitstatus) + end + + # If #error? is true, calls +invalid!+, which raises an Exception. # === Returns # nil::: always returns nil when it does not raise # === Raises # ::ShellCommandFailed::: via +invalid!+ def error! - unless Array(valid_exit_codes).include?(exitstatus) - invalid!("Expected process to exit with #{valid_exit_codes.inspect}, but received '#{exitstatus}'") - end + invalid!("Expected process to exit with #{valid_exit_codes.inspect}, but received '#{exitstatus}'") if error? end # Raises a ShellCommandFailed exception, appending the |