Browse Source

crash reporter: send traceback for full chain of exceptions

Previously if there was a chain of exceptions, we were only
sending the traceback for the final exception.

E.g.
try:
    raise ExcOne("asdasd")
except ExcOne() as e:
    raise ExcTwo("qweqwe") from e

^ we would lose all info about ExcOne, including potentially many lines of trace
patch-4
SomberNight 4 years ago
parent
commit
d0f0669e8f
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 13
      electrum/base_crash_reporter.py
  2. 4
      electrum/gui/qt/exception_window.py

13
electrum/base_crash_reporter.py

@ -81,7 +81,7 @@ class BaseCrashReporter(Logger):
def get_traceback_info(self):
exc_string = str(self.exc_args[1])
stack = traceback.extract_tb(self.exc_args[2])
readable_trace = "".join(traceback.format_list(stack))
readable_trace = self.__get_traceback_str_to_send()
id = {
"file": stack[-1].filename,
"name": stack[-1].name,
@ -109,12 +109,19 @@ class BaseCrashReporter(Logger):
pass
return args
def _get_traceback_str(self) -> str:
def __get_traceback_str_to_send(self) -> str:
# make sure that traceback sent to crash reporter contains
# e.__context__ and e.__cause__, i.e. if there was a chain of
# exceptions, we want the full traceback for the whole chain.
return "".join(traceback.format_exception(*self.exc_args))
def _get_traceback_str_to_display(self) -> str:
# overridden in Qt subclass
return self.__get_traceback_str_to_send()
def get_report_string(self):
info = self.get_additional_info()
info["traceback"] = self._get_traceback_str()
info["traceback"] = self._get_traceback_str_to_display()
return self.issue_template.format(**info)
def get_user_description(self):

4
electrum/gui/qt/exception_window.py

@ -145,11 +145,11 @@ class Exception_Window(BaseCrashReporter, QWidget, MessageBoxMixin, Logger):
wallet_types = Exception_Hook._INSTANCE.wallet_types_seen
return ",".join(wallet_types)
def _get_traceback_str(self) -> str:
def _get_traceback_str_to_display(self) -> str:
# The msg_box that shows the report uses rich_text=True, so
# if traceback contains special HTML characters, e.g. '<',
# they need to be escaped to avoid formatting issues.
traceback_str = super()._get_traceback_str()
traceback_str = super()._get_traceback_str_to_display()
return html.escape(traceback_str)

Loading…
Cancel
Save