Exception notes are printed in tracebacks, but they are omitted when an exception is handled and logged or printed. I think a possibly helpful information is lost.
# Python 3.11+
enote = ValueError("error message")
enote.add_note("additional info")
try:
raise enote
except Exception as exc:
print(repr(exc)) # will NOT print 'additional info'
Unless I overlooked something, the PEP 678 does not discuss the string representation, just the tracebacks. The output format was not changed when notes were introduced:
ValueError('error message')
I find a format like the one below better suited for exceptions with notes:
<exception=ValueError('error message'), notes=('additional info',)>
However, I guess that a change in BaseExcpeption.__repr__
could break some existing code and is quite unlikely for that reason. An alternative proposal may emerge in the discussion, I’m sorry for not giving a fully specified proposal.
I know it takes just few lines of conditional text formatting, but does everyone know that without some special effort some information may remain hidden? Especially, when the standard way of printing an error was just fine in the past. So my concern is that the status quo goes against the purpose of exception notes to give extra information that is not separated from the error itself.