pylint-bot / test

0 stars 0 forks source link

Preserve tracebacks on Python 2 #176

Closed pylint-bot closed 8 years ago

pylint-bot commented 8 years ago

Originally reported by: BitBucket: ceridwenv, GitHub: @ceridwen?


In debugging, I noticed that on Python 2 in certain circumstances it's possible for exceptions in the inference mechanisms to end up losing the traceback up to the point they're raised. (Python3 always chains exceptions that are raised while processing another exception, I think.) The best way I know of to do this is probably with six.reraise, but I'm open to other suggestions.


pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


That sounds good, there are a lot of places where exceptions are reraised, without considering the loss of the traceback.

pylint-bot commented 8 years ago

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


I'm aware of raise ObjectNotFound(name).with_traceback(sys.exc_info()[-1]) (py3) or raise ObjectNotFound(name), None, sys.exc_info()[-1] (py2)

pylint-bot commented 8 years ago

Original comment by BitBucket: ceridwenv, GitHub: @ceridwen?:


My problem when attempting this has turned out to be that I don't understand the code paths well enough to know where exceptions can be raised ultimately within an except block. I can simply try to change all the places where exceptions are being raised, or if anyone has more understanding of the code paths, I could try to focus on those.

pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


We could focus only on the places where exceptions are being raised, since otherwise we might have tracebacks from the entire inference chain and I'm not sure how useful that would be. In that case, something as oslo.excutils.save_and_reraise_exception could be used: http://docs.openstack.org/developer/oslo.utils/api/excutils.html#oslo_utils.excutils.save_and_reraise_exception

pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


Fixed by https://bitbucket.org/logilab/astroid/pull-requests/88/use-sixreraise-to-avoid-losing-tracebacks