Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture correct tracebacks when using inline_callbacks. #475

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomprince
Copy link
Contributor

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 use Failure, instead of an
exc_info tuple, when used via inline_callabcks.

[1] The string-ified traceback can't be passed to .send.

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 use `Failure`, instead of an
exc_info tuple, when used via `inline_callabcks`.


[1] The string-ified traceback can't be passed to `.send`.
@itamarst
Copy link
Owner

itamarst commented Jul 15, 2021 via email

@itamarst
Copy link
Owner

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.

@itamarst
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracebacks going through eliot.twisted.inline_callbacks lose some important frames at the end
2 participants