[Python-Dev] [Python-checkins] cpython: Close #17828: better handling of codec errors

Stefan Behnel stefan_ml at behnel.de
Fri Nov 15 08:22:59 CET 2013

Nick Coghlan, 13.11.2013 17:25:
> Note that the specific problem with just annotating the exception
> rather than a specific frame is that you lose the stack context for
> where the annotation occurred. The current chaining workaround doesn't
> just change the exception message, it also breaks the stack into two
> pieces (inside and outside the codec) that get displayed separately.

I find this specific chain of exceptions a bit excessive, though:

Failed example:
    Traceback (most recent call last):
    LookupError: unknown encoding: UCS4
    LookupError: unknown encoding: UCS4
    The above exception was the direct cause of the following exception:
    Traceback (most recent call last):
      File ".../py3km/python/lib/python3.4/doctest.py", line 1291, in __run
        compileflags, 1), test.globs)
      File "<doctest xpathxslt.txt[89]>", line 1, in <module>
      File "xslt.pxi", line 727, in lxml.etree._XSLTResultTree.__str__
      File "xslt.pxi", line 750, in lxml.etree._XSLTResultTree.__unicode__
    LookupError: decoding with 'UCS4' codec failed (LookupError: unknown
encoding: UCS4)

I can't see any bit of information being added by chaining the exceptions
in this specific case.

Remember that each change to exception messages and/or exception chaining
will break someone's doctests somewhere, and it's really ugly to work
around chained exceptions in (cross-Py-version) doctests.

I understand that this is helpful *in general*, though, i.e. for other
kinds of exceptions in codecs, so maybe changing the exception handling in
the doctest module could be a work-around for this kind of change?


More information about the Python-Dev mailing list