Raise the "original" exception from Interpreter.run()? #43
Labels
complexity: medium
moderately hard to figure out
P2
low priority
size: medium
requires a moderate amount of changes
type: enhancement
X [cross-interpreter]
e.g. channels
(Note that this is more of a future enhancement than a blocker for PEP 554, etc.)
from PEP 554:
Currently uncaught exceptions from
Interpreter.run()
are stringified and then wrapped in aRunFailedError
before being raised in the calling interpreter. With that you can always know if an uncaught exception came from a subinterpreter. On top of that, in #17 we're addressing the issue of lost information for the propagated exception (e.g. type, attrs, traceback,__cause__
). Once that is resolved the boundary between the two interpreters will be clear and the traceback informative about the course of events.At that point, however, you still always have to deal with
RunFailedError
if you otherwise don't care that the exception came from another interpreter (which I expect most folks won't). This leads to annoying boilerplate code. In #17 the example demonstrates some of the clunkiness.We can address this, but must remember there's sometimes value to knowing that an exception came out of another interpreter. So we shouldn't just throw that information away either. That said, there's perhaps even more value to not requiring boilerplate code.
Here are some options for handling the original exception more easily:
A. raise the propagated exception directly in the calling interpreter
B. like A, but set
__cause__
on the exception to theRunFailedError
C. like B, but set
__propagated__
insteadD. raise
RunFailedError
and re-raise original viaRunFailedError.raise()
(or.reraise()
)E. provide a context manager that re-raises the "original" exception
Contrast the example in #17 with the alternatives presented above:
A:
You don't have to treat the unhandled exception specially, but you lose context. Perhaps you could get it back by walking the traceback looking for the point that
interp.run()
is called (there could even be a helper for that). However, at the very least the traceback won't be nearly as useful.B:
Then you get the best of both worlds (at the expense of an inversion of the exception chain):
C:
Like B, but doesn't reverse the meaning of
__cause__
. However, either the traceback machinery would have to know how to deal with__propagated__
or we lose the information.D:
...
E:
...
The text was updated successfully, but these errors were encountered: