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.
This commit is contained in:
Nils Vu 2022-07-16 14:01:38 +02:00
parent aea574a215
commit 0817587669
No known key found for this signature in database
GPG Key ID: F135063A8FCFACA0
2 changed files with 5 additions and 6 deletions

View File

@ -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)

View File

@ -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__