gh-108791: Fix pdb CLI invalid argument handling#108816
gh-108791: Fix pdb CLI invalid argument handling#108816iritkatriel merged 10 commits intopython:mainfrom chgnrdv:pdb-cli-fix-error-handling
pdb CLI invalid argument handling#108816Conversation
`pdb` module, if invoked with invalid command line arguments, produces large traceback and/or tries to run debugger on errorneus target, such as directory. This patch improves error handling in pdb CLI, making error messages more concise.
|
I had to make changes in |
…on into pdb-cli-fix-error-handling
Lib/pdb.py
Outdated
| except Exception: | ||
| traceback.print_exc() | ||
| except Exception as e: | ||
| print(f"{type(e).__name__}: {e}") |
There was a problem hiding this comment.
Can you make it something like
try:
self._details
except ... : # Something you expect
print(f"{type(e).__name__}: {e}")
except Exception:
traceback.print_exc()to leave the general case untouched.
There was a problem hiding this comment.
Looking at the runpy._get_module_details source, ImportError seems to be the only type of exception that can be raised here.
gaogaotiantian
left a comment
There was a problem hiding this comment.
I think the improvement is fine. The argument parser piece is a bit hacky, but I'm planning to convert that part to argparse anyway (getopt has not been updated for like 10 years) so it's okay.
|
Hi @chgnrdv , as I updated pdb to use |
|
@gaogaotiantian, thanks for notice, I'll take a look tomorrow. |
|
LGTM, @iritkatriel could you take a look? Thanks! |
|
LGTM. Should this be backported? |
|
Rare case, but safe and backward compatible. I think it should be back-ported. |
|
Agreed |
|
Thanks @chgnrdv for the PR, and @iritkatriel for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
…8816) (cherry picked from commit 162213f) Co-authored-by: Radislav Chugunov <[email protected]>
|
GH-110915 is a backport of this pull request to the 3.12 branch. |
|
GH-110916 is a backport of this pull request to the 3.11 branch. |
…8816) (cherry picked from commit 162213f) Co-authored-by: Radislav Chugunov <[email protected]>
|
GH-111063 is a backport of this pull request to the 3.11 branch. |
|
GH-111064 is a backport of this pull request to the 3.12 branch. |
Fixes #108791.
pdbmodule, if invoked with invalid command line arguments, produces large traceback and/or tries to run debugger on errorneus target, such as directory. This patch improves error handling in pdb CLI, making error messages more concise.pdbCLI doesn't handle incorrect arguments properly #108791