Skip to content

Commit

Permalink
Fix case where some Exceptions have no traceback.
Browse files Browse the repository at this point in the history
In chained exception if some exceptions does not have tracebacks,
prevent jumping to them.

We also add the assert that the main exception does have a traceback.

This is a port of python/cpython commit 5f3433f210d25d366fcebfb40adf444c8f46cd59
  • Loading branch information
Carreau committed Sep 6, 2023
1 parent 7ad98de commit 6bf247d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,25 @@ def do_exceptions(self, arg):
rep = repr(exc)
if len(rep) > 80:
rep = rep[:77] + "..."
self.message(f"{prompt} {ix:>3} {rep}")
indicator = (
" -"
if self._chained_exceptions[ix].__traceback__ is None
else f"{ix:>3}"
)
self.message(f"{prompt} {indicator} {rep}")
else:
try:
number = int(arg)
except ValueError:
self.error("Argument must be an integer")
return
if 0 <= number < len(self._chained_exceptions):
if self._chained_exceptions[number].__traceback__ is None:
self.error(
"This exception does not have a traceback, cannot jump to it"
)
return

self._chained_exception_index = number
self.setup(None, self._chained_exceptions[number].__traceback__)
self.print_stack_entry(self.stack[self.curindex])
Expand All @@ -438,6 +449,8 @@ def interaction(self, frame, tb_or_exc):
if CHAIN_EXCEPTIONS:
# this context manager is part of interaction in 3.13
_chained_exceptions, tb = self._get_tb_and_exceptions(tb_or_exc)
if isinstance(tb_or_exc, BaseException):
assert tb is not None, "main exception must have a traceback"
with self._hold_exceptions(_chained_exceptions):
OldPdb.interaction(self, frame, tb)
else:
Expand Down

0 comments on commit 6bf247d

Please sign in to comment.