Message362648
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). |
|
Date |
User |
Action |
Args |
2020-02-25 16:15:36 | João Eiras | set | recipients:
+ João Eiras |
2020-02-25 16:15:36 | João Eiras | set | messageid: <1582647336.17.0.517223219132.issue39750@roundup.psfhosted.org> |
2020-02-25 16:15:36 | João Eiras | link | issue39750 messages |
2020-02-25 16:15:35 | João Eiras | create | |
|