From cf00f20e111622ce26319b2aea5a9f50448667d7 Mon Sep 17 00:00:00 2001 From: William Vu Date: Thu, 18 Oct 2018 22:38:10 -0500 Subject: [PATCH] Update Net::SSH::CommandStream exception handling --- lib/net/ssh/command_stream.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/net/ssh/command_stream.rb b/lib/net/ssh/command_stream.rb index 0bf40ff864..79e00b6535 100644 --- a/lib/net/ssh/command_stream.rb +++ b/lib/net/ssh/command_stream.rb @@ -16,7 +16,10 @@ class CommandStream end def shell_requested(channel, success) - raise "could not request ssh shell" unless success + unless success + raise Net::SSH::ChannelRequestFailed, 'shell/exec channel request failed' + end + channel[:data] = '' channel.on_eof do @@ -27,7 +30,7 @@ class CommandStream cleanup end - channel.on_data do |ch,data| + channel.on_data do |ch, data| self.rsock.write(data) end @@ -57,7 +60,7 @@ class CommandStream # A PTY will write us to {u,w}tmp and lastlog rch.request_pty if rpty if rcmd.nil? - rch.send_channel_request("shell", &method(:shell_requested)) + rch.send_channel_request('shell', &method(:shell_requested)) else rch.exec(rcmd, &method(:shell_requested)) end @@ -78,6 +81,7 @@ class CommandStream end rescue ::Exception => e + # XXX: This won't be set UNTIL there's a failure from a thread self.error = e #::Kernel.warn "BOO: #{e.inspect}" #::Kernel.warn e.backtrace.join("\n")