-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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-108791: Fix pdb
CLI invalid argument handling
#108816
Conversation
`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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the runpy._get_module_details
source, ImportError
seems to be the only type of exception that can be raised here.
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.
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. |
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. |
…onGH-108816) (cherry picked from commit 162213f) Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
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.
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.pdb
CLI doesn't handle incorrect arguments properly #108791