Closed goldcode closed 7 years ago
If we were to attach the original stack trace to the TaskError, I prefer using the raise ... from ...
syntax. Then the original exception will be available at e.__cause__
I think you're looking for e.__traceback__
? But yeah, if you just want to preserve the traceback while propagating the exception to another task, reraising the exception object, or using raise ... from ...
will do that, because exception objects carry their traceback with them.
I'm pretty sure that e.__cause__.__traceback__
would have the traceback. Definitely in the weeds a bit once the exception chains start to get long though...
Oh right, I forgot the TaskError
wrapping... e.__cause__
is how you get the original exception.
i think i figured out what my problem actually was. Below gives information about the entire exception chain.
except curio.TaskError as te:
tuple_strings = traceback.format_exception(curio.TaskError, te, None)
message = ''.join(tuple_strings)
as opposed to only the top most exception traceback like so.
message = ''.join(traceback.format_tb(te.__cause__.__traceback__))
running the above outputs the following below. however i am unable to access the stack of the crashing task- child in this case.
how would i access this? If not accessible, would it be possible to pin either the task or the TaskError exception object with the sys.exc_info of the crashing task? it's useful for rerouting this information to other programs in my case for faster error handling.