-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-80731: Avoid executing code in except block in cmd #111740
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
gh-80731: Avoid executing code in except block in cmd #111740
Conversation
|
How does this PR compare with #4666? |
Oh I did not see that PR. I believe the purpose is the same. I don't think we need to "avoid raising any exception", because it seems like as long as we are not doing the work in the |
serhiy-storchaka
left a comment
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 change can also be tested without debugger.
Add a test in test_cmd for default() raising an exception and check __context__ and __cause__ of the exception.
Sure, I added a test to check the correct exception can be retrieved in |
|
Thank you for your contribution @gaogaotiantian. The advantage of this PR is that it contains tests. But #4666 has also changes in the |
The So in my opinion, #4666 can be closed because the problem it tries to solve is solved. |
Currently
cmd.Cmdexecutes code in anexceptblock if no command is found. This is not ideal because exception info likesys.exc_info()would break. Specifically, inpdb, the users won't be able to see the exception they want, instead they get anAttributeErrorfromcmd.Cmd.The fix is pretty trivial - just don't do it in the
exceptblock. Here I used default value forgetattr, which is probably cleaner. It's equivalent to moving theself.default()function call outside of theexceptblock.