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

Confusing combined traceback when exception thrown after inlineCallbacks generator returns #10260

Closed
twisted-trac opened this issue Sep 14, 2021 · 2 comments

Comments

@twisted-trac
Copy link

taliastocks's avatar @taliastocks reported
Trac ID trac#10260
Type enhancement
Created 2021-09-14 18:26:41Z

In the current release, if an inlineCallback generator returns to a deferred callback that throws an exception, the traceback is confusing, e.g.:

Traceback (most recent call last):
  File "/mnt/mesos/sandbox/.pex/install/Twisted-20.3.0-cp37-cp37m-manylinux1_x86_64.whl.1128a7e2b98487eb88697f10720d146583a69992/Twisted-20.3.0-cp37-cp37m-manylinux1_x86_64.whl/twisted/internet/defer.py", line 1418, in _inlineCallbacks
    result = g.send(result)
StopIteration: Response(code=200, message=b'OK')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/mesos/sandbox/__main__-D229445.750890.pex/infra_compute/proxy/proxy.py", line 291, in _proxy_request
    simplified_response = yield self.proxy.process_request(simplified_request)
... # the real traceback we care about

This happens because the status.deferred.callback() is called from within the StopIteration exception handler. Python assumes that the StopIteration is the real exception we care about because that exception was being handled while the second exception was thrown. However, we don't care about the StopIteration exception, as it is only used to transmit a return value from the inlineCallback generator.

This can be avoided by first exiting the exception handler, then calling status.deferred.callback(). Python will no longer incorrectly tack on the StopIteration traceback on the top if there is an exception in the callback.

Searchable metadata
trac-id__10260 10260
type__enhancement enhancement
reporter__taliastocks taliastocks
priority__normal normal
milestone__None None
branch__ 
branch_author__ 
status__closed closed
resolution__fixed fixed
component__core core
keywords__None None
time__1631644001617490 1631644001617490
changetime__1656137306906475 1656137306906475
version__None None
owner__None None
cc__taliastocks
@twisted-trac
Copy link
Author

taliastocks's avatar @taliastocks commented

Fixed in #1662

@twisted-trac
Copy link
Author

twm's avatar @twm set status to closed

Merged here: ee0728c

Big thanks to Talia for the patch and Adi for review!

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

No branches or pull requests

1 participant