Open tomprince opened 3 years ago
Thank you! I’m on vacation so will take a look when I return to work.
On Wed, Jul 14, 2021, at 4:21 PM, Tom Prince wrote:
Fixes #449 https://github.com/itamarst/eliot/issues/449. I'm not sure if this a great solution, but it appears to fix the issue by letting Failure's stack walking find the right context.
When an inlineCallback completes synchronously, such as in tests, twisted will string-ify the traceback, which means that when the exception is then thrown into another inlineCallback function, the stack trace is lost[1]. Twisted works around this by inspect the stack and finding the Failure instance from the inner call, to get traceback there.
However, this only works if
Failure.throwExceptionIntoGenerator
is used. This adjusts eliot_friendly_generator_function to useFailure
, instead of an exc_info tuple, when used viainline_callabcks
.[1] The string-ified traceback can't be passed to
.send
.You can view, comment on, or merge this pull request online at:
https://github.com/itamarst/eliot/pull/475
Commit Summary
Capture correct tracebacks when using
inline_callbacks
. File ChangesM eliot/_generators.py https://github.com/itamarst/eliot/pull/475/files#diff-5fc6644f84f001efb26cd38bfda600a55068805cc22052597de4b961fb7bab98 (13)
M eliot/twisted.py https://github.com/itamarst/eliot/pull/475/files#diff-101a2db4879f60ddd510d70a8f315d1c4906420660b6ba170b01402bb0c7cb6c (1) Patch Links:
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/itamarst/eliot/pull/475, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAY5QZREBZMMQVHBZUDAI63TXYLZNANCNFSM5AMMZ56A.
-- Itamar Turner-Trauring
Thanks for your patience on a review.
This seems, apriori, fine? If the worry is breaking abstractions, inline callbacks is really the only use case for the generators code, so that seems OK.
So happy to merge this given a test.
A new version of Twisted has just been released, and at this point the contextvars
support in Twisted is probably good enough that normal inlineCallbacks
should just work correctly (plus async/await
!), with no need for special code in Eliot. If it's still relevant, do you want to try that and see if it works for you?
Fixes #449. I'm not sure if this a great solution, but it appears to fix the issue by letting Failure's stack walking find the right context.
When an inlineCallback completes synchronously, such as in tests, twisted will string-ify the traceback, which means that when the exception is then thrown into another inlineCallback function, the stack trace is lost[1]. Twisted works around this by inspect the stack and finding the Failure instance from the inner call, to get traceback there.
However, this only works if
Failure.throwExceptionIntoGenerator
is used. This adjusts eliot_friendly_generator_function to useFailure
, instead of an exc_info tuple, when used viainline_callabcks
.[1] The string-ified traceback can't be passed to
.send
.