Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

"better" error handling #55

Open
wants to merge 3 commits into from

1 participant

@ralph-tice

This is intended as a conversation starter about how to make the error messages better rather than always throwing a NoServersAvailable and as a counterpoint to d8ad596

Maybe this is better tackled in thrift itself but that seems even hairier...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
1  lib/thrift_client.rb
@@ -5,6 +5,7 @@
class ThriftClient < AbstractThriftClient
class NoServersAvailable < StandardError; end
+ class TransportError < StandardError; end
=begin rdoc
Create a new ThriftClient instance. Accepts an internal Thrift client class (such as CassandraRb::Client), a list of servers with ports, and optional parameters.
View
13 lib/thrift_client/abstract_thrift_client.rb
@@ -216,6 +216,19 @@ def transport_can_timeout?
end
def no_servers_available!
+ errors = []
+ begin
+ @server_list.collect { |srv|
+ error_msg = srv.connection.transport.instance_variable_get(:@rbuf).force_encoding("ASCII-8BIT").gsub("\f", ' ').scan(/[[:print:]]/).join
+ errors << "Error on server #{srv} : #{error_msg}" unless error_msg.blank?
+ }
+ rescue
+ #this is OK because we intend to immediately re-raise an exception
+ end
+ if errors.any?
+ raise ThriftClient::TransportError, errors[0] unless errors.count > 1
+ raise ThriftClient::TransportError, errors.inspect
+ end
raise ThriftClient::NoServersAvailable, "No live servers in #{@server_list.inspect}."
end
end
Something went wrong with that request. Please try again.