TSocket hides underlying exceptions when open() fails 
------------------------------------------------------

                 Key: THRIFT-792
                 URL: https://issues.apache.org/jira/browse/THRIFT-792
             Project: Thrift
          Issue Type: Bug
          Components: Library (Python)
    Affects Versions: 0.2
         Environment: Linux & Python 2.6
            Reporter: tholzer
            Priority: Minor


When opening a socket via Thrift, the exception message simply says:

"Could not connect to localhost:9160"

The underlying OS error is lost. This is a classic example of the anti-pattern 
called "exception masquerading". The exception handler loses essential 
information related to the source of the error. This makes troubleshooting 
difficult.

The problem lies inside TSocket.py, the original socket.error is simply 
discarded:
{noformat} 
try:
  ... connect() ...
except socket.error, e:
      ...
      message = 'Could not connect to %s:%d' % (self.host, self.port)
      raise TTransportException(TTransportException.NOT_OPEN, message)
{noformat} 

To reproduce

{noformat}thrift.transport.TSocket.TSocket().open(){noformat} 

Excpected behaviour:

The TTransportException should carry as much information as possible relating 
to the original error, e.g.:

Could not connect to (localhost:9090): (<class 'socket.error'>, error(111, 
'Connection refused'))

The TTransportException should carry the real exception it was trying to hide 
as a member variable so that the caller can take appropriate action in case of 
transient failures (e.g. EINTR).


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to