Permalink
Browse files

Add useful debugging information to ReadTimeoutError

  • Loading branch information...
defunkt authored and mojombo committed Nov 26, 2009
1 parent ea1bf6f commit 0cec2090ddaa0ad868377e5dad3ea741cd476081
Showing with 11 additions and 3 deletions.
  1. +1 −1 lib/bertrpc/action.rb
  2. +8 −2 lib/bertrpc/errors.rb
  3. +2 −0 test/action_test.rb
View
@@ -45,7 +45,7 @@ def transaction(bert_request)
rescue Errno::ECONNREFUSED
raise ConnectionError.new("Unable to connect to #{@svc.host}:#{@svc.port}")
rescue Timeout::Error
- raise ReadTimeoutError.new("No response from #{@svc.host}:#{@svc.port} in #{@svc.timeout}s")
+ raise ReadTimeoutError.new(@svc.host, @svc.port, @svc.timeout)
end
# Creates a socket object which does speedy, non-blocking reads
View
@@ -28,8 +28,14 @@ class ConnectionError < BERTRPCError
end
+ # Raised when we don't get a response from a server in a timely
+ # manner. This typically occurs in spite of a successful connection.
class ReadTimeoutError < BERTRPCError
-
+ attr_reader :host, :port, :timeout
+ def initialize(host, port, timeout)
+ @host, @port, @timeout = host, port, timeout
+ super("No response from #{host}:#{port} in #{timeout}s")
+ end
end
class ProtocolError < BERTRPCError
@@ -52,4 +58,4 @@ class ProxyError < BERTRPCError
class InvalidOption < BERTRPCError
end
-end
+end
View
@@ -101,6 +101,8 @@ class ActionTest < Test::Unit::TestCase
fail "Should have thrown an error"
rescue BERTRPC::ReadTimeoutError => e
assert_equal 0, e.code
+ assert_equal 'localhost', e.host
+ assert_equal 9941, e.port
end
end
end

0 comments on commit 0cec209

Please sign in to comment.