format exception using traceback.format_exception_only for error messages

because many exceptions return empty strings for `str(exc)`, or lack
information (e.g. the exception name).
This commit is contained in:
lilydjwg 2022-04-06 13:54:34 +08:00
parent 253f97a3e9
commit 65e4f18bb4

View File

@ -538,10 +538,11 @@ class UIBase:
exitstatus = 1
while not self.exc_queue.empty():
msg, exc, exc_traceback = self.exc_queue.get()
exc_str = "".join(traceback.format_exception_only(type(exc), exc))
if msg:
self.warn("ERROR: %s\n %s" % (msg, exc))
self.warn("ERROR: %s\n %s" % (msg, exc_str))
else:
self.warn("ERROR: %s" % exc)
self.warn("ERROR: %s" % exc_str)
if exc_traceback:
self.warn("\nTraceback:\n%s" % "".join(
traceback.format_tb(exc_traceback)))