Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
102 changes: 85 additions & 17 deletions Lib/idlelib/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,30 +250,98 @@ def print_exception():
sys.last_exc = val
seen = set()

def print_exc(typ, exc, tb):
def print_exc(typ, exc, tb, prefix=""):
Comment thread
gpshead marked this conversation as resolved.
seen.add(id(exc))
context = exc.__context__
cause = exc.__cause__
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
"debugger_r.py", "bdb.py")
if cause is not None and id(cause) not in seen:
print_exc(type(cause), cause, cause.__traceback__)
print("\nThe above exception was the direct cause "
"of the following exception:\n", file=efile)
print_exc(type(cause), cause, cause.__traceback__, prefix)
if prefix:
print(f"{prefix}|\n{prefix}| The above exception was the direct cause "
f"of the following exception:\n{prefix}|", file=efile)
else:
print("\nThe above exception was the direct cause "
"of the following exception:\n", file=efile)
elif (context is not None and
not exc.__suppress_context__ and
id(context) not in seen):
print_exc(type(context), context, context.__traceback__)
print("\nDuring handling of the above exception, "
"another exception occurred:\n", file=efile)
if tb:
tbe = traceback.extract_tb(tb)
print('Traceback (most recent call last):', file=efile)
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
"debugger_r.py", "bdb.py")
cleanup_traceback(tbe, exclude)
traceback.print_list(tbe, file=efile)
lines = get_message_lines(typ, exc, tb)
for line in lines:
print(line, end='', file=efile)
print_exc(type(context), context, context.__traceback__, prefix)
if prefix:
print(f"{prefix}|\n{prefix}| During handling of the above exception, "
f"another exception occurred:\n{prefix}|", file=efile)
else:
print("\nDuring handling of the above exception, "
"another exception occurred:\n", file=efile)
if isinstance(exc, BaseExceptionGroup):
Comment thread
gpshead marked this conversation as resolved.
if tb:
if not prefix:
Comment thread
gpshead marked this conversation as resolved.
Outdated
print(" + Exception Group Traceback (most recent call last):", file=efile)
else:
print(f"{prefix}| Exception Group Traceback (most recent call last):", file=efile)
tbe = traceback.extract_tb(tb)
cleanup_traceback(tbe, exclude)
for line in traceback.format_list(tbe):
for subline in line.rstrip().splitlines():
if not prefix:
print(f" | {subline}", file=efile)
else:
print(f"{prefix}| {subline}", file=efile)
Comment thread
Locked-chess-official marked this conversation as resolved.
Outdated
lines = get_message_lines(typ, exc, tb)
for line in lines:
if not prefix:
print(f" | {line}", end="", file=efile)
else:
print(f"{prefix}| {line}", end="", file=efile)

for i, sub in enumerate(exc.exceptions, 1):
if i == 1:
first_line_pre = "+-"
else:
first_line_pre = " "
if not prefix:
print(f" {first_line_pre}+---------------- {i} ----------------", file=efile)
Comment thread
gpshead marked this conversation as resolved.
Outdated
else:
print(f"{prefix}{first_line_pre}+---------------- {i} ----------------", file=efile)
if id(sub) not in seen:
if not prefix:
print_exc(type(sub), sub, sub.__traceback__, " ")
else:
print_exc(type(sub), sub, sub.__traceback__, prefix + " ")
need_print_underline = not isinstance(sub, BaseExceptionGroup)
else:
if not prefix:
print("f | <exception {type(sub).__name__} has printed>")
else:
print(f"{prefix} | <exception {type(sub).__name__} has printed>")
need_print_underline = True
if need_print_underline:
if not prefix:
print(" +------------------------------------", file=efile)
else:
print(f" {prefix}+------------------------------------", file=efile)

else:
if tb:
if prefix:
print(f"{prefix}| Traceback (most recent call last):", file=efile)
else:
print("Traceback (most recent call last):", file=efile)
tbe = traceback.extract_tb(tb)
cleanup_traceback(tbe, exclude)
if prefix:
for line in traceback.format_list(tbe):
for subline in line.rstrip().splitlines():
print(f"{prefix}| {subline}", file=efile)
else:
traceback.print_list(tbe, file=efile)
lines = get_message_lines(typ, exc, tb)
for line in lines:
if prefix:
print(f"{prefix}| {line}", end="", file=efile)
else:
print(line, end='', file=efile)

print_exc(typ, val, tb)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add the support with BaseExceptionGroup in IDLE
Comment thread
Locked-chess-official marked this conversation as resolved.
Outdated
Loading