gh-80731: Avoid executing code in except block in cmd#111740
gh-80731: Avoid executing code in except block in cmd#111740serhiy-storchaka merged 4 commits intopython:mainfrom
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.
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.