From 0817587669a9f75cb58f836ac1f1255cc289e9df Mon Sep 17 00:00:00 2001 From: Nils Vu Date: Sat, 16 Jul 2022 14:01:38 +0200 Subject: [PATCH] Print cause of exceptions even when they have no traceback For example, exceptions raised by 'multiprocessing' may not include a traceback. Instead, they include the traceback from another process formatted as a string in the description of the exception. It contains important information, so it should be printed by rich. --- CONTRIBUTORS.md | 1 + rich/traceback.py | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8b49afe5..e68a05b4 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -43,6 +43,7 @@ The following people have contributed to the development of Rich: - [Nicolas Simonds](https://github.com/0xDEC0DE) - [Aaron Stephens](https://github.com/aaronst) - [Gabriele N. Tornetta](https://github.com/p403n1x87) +- [Nils Vu](https://github.com/nilsvu) - [Arian Mollik Wasi](https://github.com/wasi-master) - [Handhika Yanuar Pratama](https://github.com/theDreamer911) - [za](https://github.com/za) diff --git a/rich/traceback.py b/rich/traceback.py index 55acaf07..5c1ac8f4 100644 --- a/rich/traceback.py +++ b/rich/traceback.py @@ -389,19 +389,17 @@ class Traceback: del stack.frames[:] cause = getattr(exc_value, "__cause__", None) - if cause and cause.__traceback__: + if cause: exc_type = cause.__class__ exc_value = cause + # __traceback__ can be None, e.g. for exceptions raised by the + # 'multiprocessing' module traceback = cause.__traceback__ is_cause = True continue cause = exc_value.__context__ - if ( - cause - and cause.__traceback__ - and not getattr(exc_value, "__suppress_context__", False) - ): + if cause and not getattr(exc_value, "__suppress_context__", False): exc_type = cause.__class__ exc_value = cause traceback = cause.__traceback__