Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Check if a exception has __cause__ before trying to access it
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren Burns committed Oct 21, 2019
1 parent 781537d commit 0fd1eb5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ward/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ def print_traceback(self, err):
trace = getattr(err, "__traceback__", "")
if trace:
trc = traceback.format_exception(None, err, trace)

if err.__cause__:
cause = err.__cause__.__class__.__name__
else:
cause = None
for line in trc:
sublines = line.split("\n")
for subline in sublines:
Expand All @@ -163,7 +166,7 @@ def print_traceback(self, err):
elif subline.lstrip().startswith("Traceback"):
cprint(content, color="blue")
elif (subline.lstrip().startswith(err.__class__.__name__) or
subline.lstrip().startswith(err.__cause__.__class__.__name__)):
(cause and subline.lstrip().startswith(cause))):
cprint(content, color="blue")
else:
print(content)
Expand Down

0 comments on commit 0fd1eb5

Please sign in to comment.