Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
Description
The Ruby thrift library raises Thrift::TransportException of three different types (NOT_OPEN, TIMED_OUT, UNKNOWN), which client libraries may want to handle in different ways. Since rescuing in Ruby is specified by exception class, providing different behavior for the different types requires rescuing all transport exceptions and checking the type.
Would the project consider introducing separate subclasses of Thrift::TransportException for the current types? Specifically:
class Thrift::TransportException::NotOpen < Thrift::TransportException class Thrift::TransportException::TimedOut < Thrift::TransportException class Thrift::TransportException::Unknown < Thrift::TransportException
This change would allow you to rewrite this code:
begin ... rescue Thrift::TransportException => ex if ex.type == Thrift::TransportException::NOT_OPEN ... else raise ex end end
as:
begin ... rescue Thrift::TransportException::NotOpen ... end
Backwards compatibility could be maintained by continuing to provide the type via the .type method, and by having Thrift::TransportException::NotOpen et. al. subclass Thrift::TransportException.
See https://github.com/twitter/thrift_client/issues/56 for additional background.