[issue45607] Make it possible to enrich an exception's error message

Zac Hatfield-Dodds report at bugs.python.org
Mon Oct 25 20:48:38 EDT 2021


Zac Hatfield-Dodds <zac.hatfield.dodds at gmail.com> added the comment:

This code shows my current best workaround based on a wrapper exception, with the traceback below annotating the additional details that I'd prefer to omit for clarity:


$ python example.py
Traceback (most recent call last):
  File "example.py", line 8, in <module>
    raise AssertionError(why)
AssertionError: Failed!
                                                                        # These lines are
The above exception was the direct cause of the following exception:    # confusing for new 
                                                                        # users, and they
Traceback (most recent call last):                                      # only exist due 
  File "example.py", line 10, in <module>                               # to implementation
    raise Explanation(msg) from e                                       # via the Explanation
Explanation:                                                            # wrapper type :-(
    You can reproduce this error by ...
    ...


The motivation for this is that we'd like to use ExceptionGroup to indicate that `MultipleFailures` is a group of exceptions, and replace our current print()-based method of reporting the details of the inner exceptions.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45607>
_______________________________________


More information about the Python-bugs-list mailing list