Issues when showing broken Exception.__notes__ #103895
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 26, 2023 - changed the title
[-]No trailing newline when showing broken `Exception .__notes__`[/-][+]Issues when showing broken `Exception.__notes__`[/+]on Apr 26, 2023 Is
Exception.__notes__supposed to be directly written?add_note()is definitely the recommended interface to use the feature. The docs mentioned__notes__as a "list of the notes", and is breaking that a "corner case", or simply the wrong way to use it?It is not supposed to be directly written (as far as I can tell), but while I was experimenting with some unrelated exception handling I was digging into this and noticed the inconsistency with the newlines so I figured I'd make a quick patch.
The only reason I bothered at all is because there's already some amount of handling of invalid notes so it seems it's at least been considered that someone may write
Exception.__notes__directly.- added a commit that references this issue
on May 1, 2023 Merged into 3.12. Leaving open pending decision about backporting to 3.11.
Reacted by Carey Metcalfe- added 2 commits that reference this issue
on May 1, 2023 Assigned to @ambv for a backport decision.
@ambv Shall we backport or close this issue?
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Nov 26, 2023
Bug report
When notes on an exception cannot be shown because the
reprandstrraise exceptions, a<note str() failed>message is shown instead. In the case whereexception.__notes__is not a sequence and cannot be shown, a<__notes__ repr() failed>is shown. In the second case, the message does not include a trailing newline.__notes__is a list containing a broken "note" - output includes a newline:__notes__is just a single broken "note" - output does not include a newline:Additionally, when
__notes__is a string/bytes, the contents are expoded over multiple lines because of anisinstance(__notes__, Sequence)check.String:
Bytes:
Even though the above are all edge cases, since there are some checks that handle these cases already, it makes sense to handle them more gracefully.
Your environment
Linked PRs
Exception.__notes__are displayed #103897