[
https://issues.apache.org/jira/browse/THRIFT-2403?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13937310#comment-13937310
]
Ryan Greenberg commented on THRIFT-2403:
----------------------------------------
I see now this is a duplicate of THRIFT-79 from [~bryanduxbury], but with an
example motivating the change. I'm happy to submit a patch with this change if
I could get some feedback about whether the project thinks the change makes
sense.
> Differentiate various TransportExceptions as separate classes
> -------------------------------------------------------------
>
> Key: THRIFT-2403
> URL: https://issues.apache.org/jira/browse/THRIFT-2403
> Project: Thrift
> Issue Type: Improvement
> Components: Ruby - Library
> Reporter: Ryan Greenberg
>
> 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:
> {code}
> class Thrift::TransportException::NotOpen < Thrift::TransportException
> class Thrift::TransportException::TimedOut < Thrift::TransportException
> class Thrift::TransportException::Unknown < Thrift::TransportException
> {code}
> This change would allow you to rewrite this code:
> {code}
> begin
> ...
> rescue Thrift::TransportException => ex
> if ex.type == Thrift::TransportException::NOT_OPEN
> ...
> else
> raise ex
> end
> end
> {code}
> as:
> {code}
> begin
> ...
> rescue Thrift::TransportException::NotOpen
> ...
> end
> {code}
> 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.
--
This message was sent by Atlassian JIRA
(v6.2#6252)