[New-bugs-announce] [issue45607] Make it possible to enrich an exception's error message
Irit Katriel
report at bugs.python.org
Mon Oct 25 16:38:01 EDT 2021
New submission from Irit Katriel <iritkatriel at gmail.com>:
The requirement comes from Hypothesis, see
https://github.com/python/cpython/pull/28569#discussion_r730338369
It is necessary there to add a note to an exception describing which test case it comes from. The note should be printed by __str__ of this exception.
class Explanation(Exception):
__module__ = "builtins"
def __str__(self) -> str:
return f"\n{self.args[0]}"
try:
why = "Failed!"
raise AssertionError(why)
except Exception as e:
msg = " You can reproduce this error by ...\n ..."
raise Explanation(msg) from e
# Ideally something more like:
e.__note__ = msg
raise
----------
components: Interpreter Core
messages: 404999
nosy: iritkatriel
priority: normal
severity: normal
status: open
title: Make it possible to enrich an exception's error message
type: enhancement
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45607>
_______________________________________
More information about the New-bugs-announce
mailing list