Issue 20105: Codec exception chaining is losing traceback details (original) (raw)

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 "", line 1, in 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 "", line 1, in 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 "", line 2, in ZeroDivisionError: division by zero

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

Traceback (most recent call last): File "", line 4, in Exception: Explicit chaining