[3.14] Improve permission error messages in pdb and asyncio.tools (GH-134290) (#138826)

Improve permission error messages in pdb and asyncio.tools (GH-134290)
(cherry picked from commit 419441a6e1)

Co-authored-by: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-09-12 14:20:20 +02:00 committed by GitHub
parent 5210e307ae
commit 664d17f97a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 109 additions and 1 deletions

View file

@ -222,6 +222,20 @@ def _print_cycle_exception(exception: CycleFoundException):
print(f"cycle: {inames}", file=sys.stderr)
def exit_with_permission_help_text():
"""
Prints a message pointing to platform-specific permission help text and exits the program.
This function is called when a PermissionError is encountered while trying
to attach to a process.
"""
print(
"Error: The specified process cannot be attached to due to insufficient permissions.\n"
"See the Python documentation for details on required privileges and troubleshooting:\n"
"https://docs.python.org/3.14/howto/remote_debugging.html#permission-requirements\n"
)
sys.exit(1)
def _get_awaited_by_tasks(pid: int) -> list:
try:
return get_all_awaited_by(pid)
@ -230,6 +244,8 @@ def _get_awaited_by_tasks(pid: int) -> list:
e = e.__context__
print(f"Error retrieving tasks: {e}")
sys.exit(1)
except PermissionError as e:
exit_with_permission_help_text()
def display_awaited_by_tasks_table(pid: int) -> None: