diff --git a/Lib/pdb.py b/Lib/pdb.py index f695a39332e461..f5d01e1e362343 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -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}") + sys.exit(1) except PermissionError as e: exit_with_permission_help_text() return diff --git a/Misc/NEWS.d/next/Library/2025-10-11-09-07-06.gh-issue-139940.g54efZ.rst b/Misc/NEWS.d/next/Library/2025-10-11-09-07-06.gh-issue-139940.g54efZ.rst new file mode 100644 index 00000000000000..55b691a42693d9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-10-11-09-07-06.gh-issue-139940.g54efZ.rst @@ -0,0 +1 @@ +Print clearer error message when using pdb to attaching to a non-existing process on Linux.