This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Codec exception chaining is losing traceback details
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: ncoghlan, python-dev
Priority: deferred blocker Keywords: 3.4regression

Created on 2014-01-02 02:23 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg207142 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-01-02 02:23
The exception chaining in the codecs subsystem is currently losing the details of the original traceback.

Compare this traceback from Python 3.3:

>>> codecs.decode(b"abcdefgh", "hex_codec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.3/encodings/hex_codec.py", line 20, in hex_decode
    return (binascii.a2b_hex(input), len(input))
binascii.Error: Non-hexadecimal digit found

With the current behaviour of Python 3.4:

>>> codecs.decode(b"abcdefgh", "hex")
binascii.Error: Non-hexadecimal digit found

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
binascii.Error: decoding with 'hex' codec failed (Error: Non-hexadecimal digit found)

The original traceback header and details are missing in the latter. It should look more like the following:

>>> try:
...     1/0
... except Exception as e:
...     raise Exception("Explicit chaining") from e
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
Exception: Explicit chaining
msg209325 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-26 14:53
New changeset b27352f87404 by Nick Coghlan in branch 'default':
Close #20105: set __traceback__ when chaining exceptions in C
http://hg.python.org/cpython/rev/b27352f87404
History
Date User Action Args
2022-04-11 14:57:56adminsetgithub: 64304
2014-01-26 14:53:52python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg209325

resolution: fixed
stage: test needed -> resolved
2014-01-02 02:23:33ncoghlancreate