Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
572 stars 91 forks source link

TProtocolException message is omitted in repr #104

Closed a-shkarupin closed 4 years ago

a-shkarupin commented 4 years ago

When getting TProtocolException in stack trace, I see no message:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/happybase/table.py", line 418, in scan
    raise e
  File "/usr/local/lib/python3.8/site-packages/happybase/table.py", line 415, in scan
    items = self.connection.client.scannerGetList(scan_id, how_many)
  File "/usr/local/lib/python3.8/site-packages/thriftpy2/thrift.py", line 219, in _req
    return self._recv(_api)
  File "/usr/local/lib/python3.8/site-packages/thriftpy2/thrift.py", line 231, in _recv
    fname, mtype, rseqid = self._iprot.read_message_begin()
  File "/usr/local/lib/python3.8/site-packages/thriftpy2/protocol/compact.py", line 145, in read_message_begin
    raise TProtocolException(TProtocolException.BAD_VERSION,
thriftpy2.protocol.exc.TProtocolException: TProtocolException(type=4)

Consider the following snippet:

Python 3.8.0 (default, Nov 23 2019, 05:36:56) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from thriftpy2.protocol.exc import TProtocolException
>>> x = TProtocolException(TProtocolException.BAD_VERSION, 'message please')
>>> x
TProtocolException(type=4)
>>> x.message
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'TProtocolException' object has no attribute 'message'
>>> x.args
('message please',)
>>> x.__dict__
{'type': 4}

Looks like this is caused by overriding the default __str__() in TPayload: https://github.com/Thriftpy/thriftpy2/blob/master/thriftpy2/thrift.py#L169

ethe commented 4 years ago

Thanks for reporting, I think it is a bug, I am thinking about fixing it.

aisk commented 4 years ago

Looks like we can avoid this issue by adding a custom __str__ on TException?

ethe commented 4 years ago

It is a good idea.