[issue20105] Codec exception chaining is losing traceback details

Nick Coghlan report at bugs.python.org
Thu Jan 2 03:23:33 CET 2014


New submission from Nick Coghlan:

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

----------
assignee: ncoghlan
components: Interpreter Core
keywords: 3.4regression
messages: 207142
nosy: ncoghlan
priority: deferred blocker
severity: normal
stage: test needed
status: open
title: Codec exception chaining is losing traceback details
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20105>
_______________________________________


More information about the Python-bugs-list mailing list