mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Improve reporting of unexpected exceptions
This commit is contained in:
parent
54dd2f8337
commit
dfde0e2310
@ -113,24 +113,27 @@ class Log:
|
||||
self.print(f"[red]{escape(text)}")
|
||||
|
||||
def unexpected_exception(self) -> None:
|
||||
t, v, tb = sys.exc_info()
|
||||
"""
|
||||
Call this in an "except" clause to log an unexpected exception.
|
||||
"""
|
||||
|
||||
t, v, tb = sys.exc_info()
|
||||
if t is None or v is None or tb is None:
|
||||
# We're not currently handling an exception, so somebody probably
|
||||
# called this function where they shouldn't.
|
||||
self.error("Something unexpected happened")
|
||||
self.error_contd("")
|
||||
for line in traceback.format_stack():
|
||||
self.error_contd(line[:-1]) # Without the newline
|
||||
self.error_contd("")
|
||||
else:
|
||||
self.error("An unexpected exception occurred")
|
||||
self.error_contd("")
|
||||
self.error_contd(traceback.format_exc())
|
||||
|
||||
for line in traceback.format_tb(tb):
|
||||
self.error_contd(line[:-1]) # Without trailing newline
|
||||
|
||||
if str(v):
|
||||
self.error_contd(f"{t.__name__}: {v}")
|
||||
else:
|
||||
self.error_contd(t.__name__)
|
||||
|
||||
self.error_contd("")
|
||||
self.error_contd("""
|
||||
An unexpected exception occurred. This usually shouldn't happen. Please copy
|
||||
your program output and send it to the PFERD maintainers, either directly or as
|
||||
a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
||||
Please copy your program output and send it to the PFERD maintainers, either
|
||||
directly or as a GitHub issue: https://github.com/Garmelon/PFERD/issues/new
|
||||
""".strip())
|
||||
|
||||
def explain_topic(self, text: str) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user