lib/net/ssh.rb in net-ssh-2.7.0 vs lib/net/ssh.rb in net-ssh-2.8.0
- old
+ new
@@ -202,18 +202,20 @@
user = options.fetch(:user, user)
if auth.authenticate("ssh-connection", user, options[:password])
connection = Connection::Session.new(transport, options)
if block_given?
- retval = yield connection
- connection.close
- retval
+ begin
+ yield connection
+ ensure
+ connection.close unless connection.closed?
+ end
else
return connection
end
else
transport.close
- raise AuthenticationFailed, user
+ raise AuthenticationFailed, "Authentication failed for user #{user}@#{host}"
end
end
# Returns a hash of the configuration options for the given host, as read
# from the SSH configuration file(s). If +use_ssh_config+ is true (the