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.

Author João Eiras
Recipients João Eiras
Date 2020-02-25.16:15:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582647336.17.0.517223219132.issue39750@roundup.psfhosted.org>
In-reply-to
Content
Given some exception `ex`, you can append data like
  ex.args += (value1, value2, ...)
and then re-raise.

This is something I do in my projects to sometime propagate context when errors are raised, e.g., stacktraces across process boundaries or blobs of text with pickling or unicode errors.

When this is done with UnicodeError, the exception becomes non-unpicklable:

  TypeError: function takes exactly 5 arguments (6 given)

Example:
    import pickle

    def test_unicode_error_unpickle():
        ex0 = UnicodeEncodeError('ascii','message', 1, 2, 'e')
        ex0.args += ("extra context",)
        ex1 = pickle.loads(pickle.dumps(ex0))
        assert type(ex0).args == type(ex1).args
        assert ex0.args == ex1.args

The issue seems to be UnicodeEncodeError_init() at https://github.com/python/cpython/blob/v3.8.1/Objects/exceptions.c#L1895 and also UnicodeDecodeError_init().

The BaseException is initialized, but then Unicode*Error_init() tries to reparse the arguments and does not tolerate extra values.

This because BaseException.__reduce__ return a tuple (class,args).
History
Date User Action Args
2020-02-25 16:15:36João Eirassetrecipients: + João Eiras
2020-02-25 16:15:36João Eirassetmessageid: <1582647336.17.0.517223219132.issue39750@roundup.psfhosted.org>
2020-02-25 16:15:36João Eiraslinkissue39750 messages
2020-02-25 16:15:35João Eirascreate