I'm using Net::SSH to connect to another server. It works fine, but I want to be able to deal with situations where it can't connect. Documentation for the method mentions nothing about exceptions, and as far as I can see it doesn't raise any. In the following example, passing a host and user that don't exist and no keys doesn't raise an exception.
The only way I can check if it failed is to look at @session, which will be nil, but this doesn't tell me anything about why it failed.
begin
@session = Net::SSH.start('no-host', 'no-user', keys: [])
rescue SocketError => e
connection_failed = true
logger.error "SOCKET ERROR: "+e.message
rescue Net::SSH::AuthenticationFailed
connection_failed = true
logger.error "AUTH ERROR: "+e.message
rescue Exception => e
logger.error "EXCEPTION: "+e.message
end
[Update] Running the following in irb raises a SocketError:
> require 'net/ssh'
> Net::SSH.start('no-host', 'no-user', keys: [])
= SocketError: getaddrinfo: nodename nor servname provided, or not known
Why doesn't this raise an exception in my app?