GeezerVison is showing github.com — gh-129605: Add more exception handling when computing suggestions in traceback.py by ADThomas-astro · Pull Request #129632 · python/cpython
Conversation
ADThomas-astro
commented
Feb 4, 2025
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
In _compute_suggestion_error in traceback.py, the code that handles AttributeError and ImportError is wrapped in try-excepts, but the code for NameError is not wrapped in a try-except. However, the hasattr(self, wrong_name) call fails if accessing an attribute raises an exception. This is what happens in the reproducer in the issue.
I wrapped the handling of NameError in a try-except to match the handling of the other two exception types.
I also added three related tests to test_traceback.py. All three of the new tests crash both PyREPL and the test_traceback.py test suite without the fix. The property test needed some creativity to trigger the bug and I'm a bit proud of it 😛
Let me know if the tests also need to be added to the PyREPL test suite.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
danielhollas reacted with heart emoji
ghost
commented
Feb 4, 2025
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement. 
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.
If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
assert isinstance(exc_value, NameError)
|
|
|
# find most recent frame
|
|
|
if tb is None:
|
|
|
try:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very broad try-except block. If you scoped it only around the hasattr call would the new test cases still pass?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ZeroIntensity and picnixz reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes they would still pass. It's usually good practice to minimise code in a try block, but I think this is an exceptional case. This function attempts to provide "Did you mean foo?" suggestions after there has already been an error in user code. Hence a different exception propagating from this function is very unhelpful (and the cause of the issue). So I think it's worth having wider try blocks here to minimise the risk of unhandled exceptions in the future. The existing code has wide try blocks ignoring all Exception subclasses when doing processing for AttributeError (L1485-1494) and ImportError (L1499-1502). I think we we should treat the processing for NameError the same. (Although - I haven't found a way to cause an exception in L1508-1517, so this is mostly theoretical.) Happy to narrow the scope of the try if folks feel strongly.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @ADThomas-astro for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Sorry, @ADThomas-astro and @ambv, I could not cleanly backport this to 3.14 due to a conflict.
Please backport manually with cherry_picker, see the devguide for more information.
cherry_picker 97b5f245136eb91bbc1aeddfcbf9bc571cedfdb5 3.14
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot x86 Debian Installed with X 3.x (tierless) has failed when building commit 97b5f24.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1244/builds/9980) and take a look at the build logs.
- Check if the failure is related to this commit (97b5f24) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/#/builders/1244/builds/9980
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
return func(*args, **kwds)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m651�[0m, in �[35mtest_interrupt�[0m
exitcode = self._kill_process(multiprocessing.Process.interrupt)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
return func(*args, **kwds)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m632�[0m, in �[35m_kill_process�[0m
self.assertEqual(�[31mjoin�[0m�[1;31m()�[0m, None)
�[31m~~~~�[0m�[1;31m^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m305�[0m, in �[35m__call__�[0m
return �[31mself.func�[0m�[1;31m(*args, **kwds)�[0m
�[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/process.py"�[0m, line �[35m156�[0m, in �[35mjoin�[0m
res = self._popen.wait(timeout)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m44�[0m, in �[35mwait�[0m
return �[31mself.poll�[0m�[1;31m(os.WNOHANG if timeout == 0.0 else 0)�[0m
�[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m28�[0m, in �[35mpoll�[0m
pid, sts = �[31mos.waitpid�[0m�[1;31m(self.pid, flag)�[0m
�[31m~~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m628�[0m, in �[35mhandler�[0m
raise RuntimeError('join took too long: %s' % p)
�[1;35mRuntimeError�[0m: �[35mjoin took too long: <Process name='Process-1' pid=3159 parent=3157 started daemon>�[0m
Traceback (most recent call last):
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
return func(*args, **kwds)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m651�[0m, in �[35mtest_interrupt�[0m
exitcode = self._kill_process(multiprocessing.Process.interrupt)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/contextlib.py"�[0m, line �[35m116�[0m, in �[35minner�[0m
return func(*args, **kwds)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m632�[0m, in �[35m_kill_process�[0m
self.assertEqual(�[31mjoin�[0m�[1;31m()�[0m, None)
�[31m~~~~�[0m�[1;31m^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m305�[0m, in �[35m__call__�[0m
return �[31mself.func�[0m�[1;31m(*args, **kwds)�[0m
�[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/process.py"�[0m, line �[35m156�[0m, in �[35mjoin�[0m
res = self._popen.wait(timeout)
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m44�[0m, in �[35mwait�[0m
return �[31mself.poll�[0m�[1;31m(os.WNOHANG if timeout == 0.0 else 0)�[0m
�[31m~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/multiprocessing/popen_fork.py"�[0m, line �[35m28�[0m, in �[35mpoll�[0m
pid, sts = �[31mos.waitpid�[0m�[1;31m(self.pid, flag)�[0m
�[31m~~~~~~~~~~�[0m�[1;31m^^^^^^^^^^^^^^^^�[0m
File �[35m"/buildbot/buildarea/3.x.ware-debian-x86.installed/build/target/lib/python3.16/test/_test_multiprocessing.py"�[0m, line �[35m628�[0m, in �[35mhandler�[0m
raise RuntimeError('join took too long: %s' % p)
�[1;35mRuntimeError�[0m: �[35mjoin took too long: <Process name='Process-170' pid=16764 parent=14673 started daemon>�[0m
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Pretty sure this PR is innocent of the "x86 Debian Installed with X 3.x" failure. Same commit, same machine, passed on "x86 Debian Non-Debug with X 3.x", build 9835 on the same worker (ware-debian-x86). It built the same 97b5f24 commit starting at 23:22:52 UTC, one second after the failing build finished. It passed, including test_multiprocessing_fork.test_processes.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Labels
stale
Stale PR or inactive for long period of time.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|