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
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion eliot/_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from contextvars import copy_context
from weakref import WeakKeyDictionary

try:
from twisted.python.failure import Failure
except ImportError:
pass

from . import log_message


Expand Down Expand Up @@ -95,6 +100,8 @@ def wrapper(*a, **kw):
def go():
if ok:
value_out = gen.send(value_in)
elif wrapper._use_failure:
value_out = value_in.throwExceptionIntoGenerator(gen)
else:
value_out = gen.throw(*value_in)
# We have obtained a value from the generator. In
Expand Down Expand Up @@ -130,9 +137,13 @@ def go():
# contextmanager. But @contextmanager extremely
# conveniently eats it for us! Thanks, @contextmanager!
ok = False
value_in = exc_info()
if wrapper._use_failure:
value_in = Failure()
else:
value_in = exc_info()
else:
ok = True

wrapper.debug = False
wrapper._use_failure = False
return wrapper
1 change: 1 addition & 0 deletions eliot/twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def inline_callbacks(original, debug=False):
function.
"""
f = eliot_friendly_generator_function(original)
f._use_failure = True
if debug:
f.debug = True
return inlineCallbacks(f)