Message362531
I think the way forward is going to be a recursive walk back to the first exception, and if __suppress_context__ is true for any exception then only the previous exception is omitted.
For example, the above example had the following chain:
Exception __context__ __cause__ __suppress_context__
--------- ----------- --------- --------------------
TypeError: None None False
KeyError: TypeError None False
KeyError: KeyError None True
When walking the stack to decide which items get printed, the final KeyError is printed (obviously, as it's the last one), but because its __suppress_context__ is True then the immediately preceding exception, the first KeyError, is skipped; however, the first KeyError's __suppress_context__ is False, so we do print its __context__, which is the TypeError. Giving us a traceback similar to:
---------------------------------------------------------------------
Traceback (most recent call last):
TypeError: str expected, not type
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
KeyError: 'NEW_VARIABLE'
---------------------------------------------------------------------
Which is entirely correct.
In cases where NewException has it's __cause__ set, we should print that as normal, then keep following the NewException.__context__ chain (with some kind of verbage or visual indicator between the __context__ and the __cause__). |
|
Date |
User |
Action |
Args |
2020-02-23 18:24:47 | ethan.furman | set | recipients:
+ ethan.furman, rhettinger, ncoghlan, benjamin.peterson, serhiy.storchaka |
2020-02-23 18:24:47 | ethan.furman | set | messageid: <1582482287.43.0.847790886088.issue39725@roundup.psfhosted.org> |
2020-02-23 18:24:47 | ethan.furman | link | issue39725 messages |
2020-02-23 18:24:47 | ethan.furman | create | |
|