diff options
author | Sarkis Varozian <svarozian@gmail.com> | 2017-11-11 08:43:09 -0800 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2018-02-21 10:05:08 -0800 |
commit | 53080b716e7a05fb8cbd3eafc37bd5196b35689c (patch) | |
tree | d3210f313e18ff19e7567d3ade1c70c5c4566bdc | |
parent | 00b9cbbc873b8302e32d4fa9ea3e9cb60d7c38ca (diff) | |
download | chef-53080b716e7a05fb8cbd3eafc37bd5196b35689c.tar.gz |
refactor on_error option
Signed-off-by: Sarkis Varozian <svarozian@gmail.com>
-rw-r--r-- | lib/chef/knife/ssh.rb | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/chef/knife/ssh.rb b/lib/chef/knife/ssh.rb index db3c6870b5..a596bfaabb 100644 --- a/lib/chef/knife/ssh.rb +++ b/lib/chef/knife/ssh.rb @@ -125,7 +125,7 @@ class Chef :long => "--exit-on-error", :description => "Immediately exit if an error is encountered", :boolean => true, - :proc => Proc.new { :raise } + :default => false option :tmux_split, :long => "--tmux-split", @@ -134,15 +134,13 @@ class Chef :default => false def session - config[:on_error] ||= :skip ssh_error_handler = Proc.new do |server| - case config[:on_error] - when :skip - ui.warn "Failed to connect to #{server.host} -- #{$!.class.name}: #{$!.message}" - $!.backtrace.each { |l| Chef::Log.debug(l) } - when :raise + if config[:on_error] #Net::SSH::Multi magic to force exception to be re-raised. throw :go, :raise + else + ui.warn "Failed to connect to #{server.host} -- #{$!.class.name}: #{$!.message}" + $!.backtrace.each { |l| Chef::Log.debug(l) } end end @@ -347,7 +345,7 @@ class Chef command = fixup_sudo(command) command.force_encoding("binary") if command.respond_to?(:force_encoding) subsession.open_channel do |chan| - if config[:on_error] == :raise && exit_status != 0 + if config[:on_error] && exit_status != 0 chan.close() else chan.request_pty |