From 3771553a2cf91ca6466117af4e35232d8e80b2ce Mon Sep 17 00:00:00 2001 From: SomberNight Date: Tue, 15 Mar 2022 13:39:33 +0100 Subject: [PATCH] crash reporter: if disabled via config, make sure EEQueue is flushed If the user had `config.get("show_crash_reporter")==False`, they would never get to see excs collected via `send_exception_to_crash_reporter(exc)`. E.g.: ``` E | gui.qt.ElectrumGui | error loading wallet (or creating window for it) Traceback (most recent call last): File "/opt/electrum/electrum/gui/qt/__init__.py", line 433, in main if not self.start_new_window(path, self.config.get('url'), app_is_starting=True): File "/opt/electrum/electrum/gui/qt/__init__.py", line 307, in wrapper return func(self, *args, **kwargs) File "/opt/electrum/electrum/gui/qt/__init__.py", line 332, in start_new_window wallet = self._start_wizard_to_select_or_create_wallet(path) File "/opt/electrum/electrum/gui/qt/__init__.py", line 377, in _start_wizard_to_select_or_create_wallet db = WalletDB(storage.read(), manual_upgrades=False) File "/opt/electrum/electrum/wallet_db.py", line 73, in __init__ self.load_data(raw) File "/opt/electrum/electrum/wallet_db.py", line 104, in load_data self._after_upgrade_tasks() File "/opt/electrum/electrum/wallet_db.py", line 202, in _after_upgrade_tasks self._load_transactions() File "/opt/electrum/electrum/util.py", line 439, in return lambda *args, **kw_args: do_profile(args, kw_args) File "/opt/electrum/electrum/util.py", line 435, in do_profile o = func(*args, **kw_args) File "/opt/electrum/electrum/wallet_db.py", line 1310, in _load_transactions self.data = StoredDict(self.data, self, []) File "/opt/electrum/electrum/json_db.py", line 79, in __init__ self.__setitem__(k, v) File "/opt/electrum/electrum/json_db.py", line 44, in wrapper return func(self, *args, **kwargs) File "/opt/electrum/electrum/json_db.py", line 97, in __setitem__ v = self.db._convert_dict(self.path, key, v) File "/opt/electrum/electrum/wallet_db.py", line 1361, in _convert_dict v = dict((k, SwapData(**x)) for k, x in v.items()) ``` --- electrum/base_crash_reporter.py | 1 + electrum/gui/kivy/uix/dialogs/crash_reporter.py | 1 + electrum/gui/qt/exception_window.py | 1 + 3 files changed, 3 insertions(+) diff --git a/electrum/base_crash_reporter.py b/electrum/base_crash_reporter.py index 10886279d..5a77f33db 100644 --- a/electrum/base_crash_reporter.py +++ b/electrum/base_crash_reporter.py @@ -146,6 +146,7 @@ class EarlyExceptionsQueue: @classmethod def set_hook_as_ready(cls): + """Flush the queue and disable it for future exceptions.""" if cls._is_exc_hook_ready: return cls._is_exc_hook_ready = True diff --git a/electrum/gui/kivy/uix/dialogs/crash_reporter.py b/electrum/gui/kivy/uix/dialogs/crash_reporter.py index d78ee32d6..49b23b78d 100644 --- a/electrum/gui/kivy/uix/dialogs/crash_reporter.py +++ b/electrum/gui/kivy/uix/dialogs/crash_reporter.py @@ -180,6 +180,7 @@ class ExceptionHook(base.ExceptionHandler, Logger): Logger.__init__(self) self.main_window = main_window if not main_window.electrum_config.get(BaseCrashReporter.config_key, default=True): + EarlyExceptionsQueue.set_hook_as_ready() # flush already queued exceptions return # For exceptions in Kivy: base.ExceptionManager.add_handler(self) diff --git a/electrum/gui/qt/exception_window.py b/electrum/gui/qt/exception_window.py index e4c0ca1f3..3be2dc735 100644 --- a/electrum/gui/qt/exception_window.py +++ b/electrum/gui/qt/exception_window.py @@ -177,6 +177,7 @@ class Exception_Hook(QObject, Logger): @classmethod def maybe_setup(cls, *, config: 'SimpleConfig', wallet: 'Abstract_Wallet' = None) -> None: if not config.get(BaseCrashReporter.config_key, default=True): + EarlyExceptionsQueue.set_hook_as_ready() # flush already queued exceptions return if not cls._INSTANCE: cls._INSTANCE = Exception_Hook(config=config)