Skip to content

Fix showing SystemExit exception raise inside except handler#14503

Merged
Carreau merged 1 commit intoipython:mainfrom
takluyver:fix/tb-chained-systemexit
Aug 29, 2024
Merged

Fix showing SystemExit exception raise inside except handler#14503
Carreau merged 1 commit intoipython:mainfrom
takluyver:fix/tb-chained-systemexit

Conversation

@takluyver
Copy link
Copy Markdown
Member

Doing something like this:

try:
    5 / 0
except Exception as e:
    raise SystemExit

was hitting an error inside UltraTB, creating a long traceback of its internals (which, ironically, UltraTB itself then displays correctly :-).

ListTB.get_exception_only() calls the ListTB.structured_traceback() method specifically - even if self is a subclass, it won't use the subclass's method. However, the exception chaining in that method uses recursion by calling self.structured_traceback(), which will use a subclass's method. Tuples were added as an option there to support exception chaining, but not all of the machinery in connected classes expects a tuple.

This just skips the exception chaining logic for the etb=None case, when we're showing the exception only. I'm not sure this is necessarily the best fix, but I didn't want to spend too much time following code around a module that's old enough to vote.

Closes #12104

@takluyver
Copy link
Copy Markdown
Member Author

It looks like the failing tests are there on main as well; they don't look like anything related to this PR.

@Carreau
Copy link
Copy Markdown
Member

Carreau commented Aug 29, 2024

Thanks !

@Carreau Carreau merged commit d5762c1 into ipython:main Aug 29, 2024
@Carreau Carreau added this to the 8.27 milestone Aug 29, 2024
@takluyver takluyver deleted the fix/tb-chained-systemexit branch September 24, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raising SystemExit leads to internal inspect module error

2 participants