Permalink
Browse files

Wrap all connection exceptions in KJess::Client::Error

This makes it simpler to see if there are any connectivity-related issues or
if the problem is somewhere else.
  • Loading branch information...
1 parent d402843 commit 9fb6143feb4d143a3f8e67edcbec3cccfcb6a746 @eric eric committed with Nov 17, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 lib/kjess/connection.rb
View
@@ -60,6 +60,8 @@ def connect
# @sock.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPINTVL, keepalive[:intvl])
# @sock.setsockopt(Socket::SOL_TCP, Socket::TCP_KEEPCNT, keepalive[:probes])
return sock
+ rescue => e
+ raise Error, "Could not connect to #{host}:#{port}: #{e.class}: #{e.message}", e.backtrace
end
# Internal: close the socket if it is not already closed
@@ -87,6 +89,9 @@ def closed?
def write( msg )
$stderr.write "--> #{msg}" if $DEBUG
socket.write( msg )
+ rescue => e
+ close
+ raise Error, "Could not write to #{host}:#{port}: #{e.class}: #{e.message}", e.backtrace
end
# Internal: read a single line from the socket
@@ -103,6 +108,9 @@ def readline( eom = Protocol::CRLF )
rescue EOFError
close
return "EOF"
+ rescue => e
+ close
+ raise Error, "Could not read from #{host}:#{port}: #{e.class}: #{e.message}", e.backtrace
end
# Internal: Read from the socket
@@ -114,6 +122,9 @@ def read( *args )
d = socket.read( *args )
$stderr.puts "<-- #{d}" if $DEBUG
return d
+ rescue => e
+ close
+ raise Error, "Could not read from #{host}:#{port}: #{e.class}: #{e.message}", e.backtrace
end
end
end

0 comments on commit 9fb6143

Please sign in to comment.