Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3577,6 +3577,11 @@ def main():
parser.error("argument -m: not allowed with argument --pid")
try:
attach(opts.pid, opts.commands)
except RuntimeError as e:
while e.__context__ is not None:
e = e.__context__
print(f"Error attaching to process: {e}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to get e here? We have opts.pid here to inform the user. I don't think the user understands this. I think the proper way here is to figure out what are the possibilities for RuntimeError. We should just let the user know that this failed, and the highest possibility is that the process does not exist.

Copy link
Author

@frostming frostming Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this is just borrowed from

def _get_awaited_by_tasks(pid: int) -> list:
try:
return get_all_awaited_by(pid)
except RuntimeError as e:
while e.__context__ is not None:
e = e.__context__
print(f"Error retrieving tasks: {e}")
sys.exit(1)
except PermissionError as e:
exit_with_permission_help_text()
to make them symmetric.

The idea here is to hide the traceback as it may contain 3+ frames that users don't know how to handle, and at the same time, don't arbitrarily cover up any fatal errors. And only the top-most frame is the real cause.

But I am okay to change to a better way.

sys.exit(1)
except PermissionError as e:
exit_with_permission_help_text()
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Print clearer error message when using pdb to attaching to a non-existing process on Linux.
Loading