Skip to content

Commit c85272b

Browse files
committed
crash reporter: only show reporter once per exception groupid
- don't show crash reporter multiple times for the "same" exception - at least until the user restart the program (there is no persistence) - this is a ~replacement for the removed "Never show crash reporter" option - in case there e.g. a thread with timer spamming an exception erroneously, this ensures we only offer to send the crash report once (per process lifecycle)
1 parent 0e0e47c commit c85272b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

electrum/base_crash_reporter.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from .i18n import _
3434
from .util import make_aiohttp_session, error_text_str_to_safe_str
3535
from .logging import describe_os_version, Logger, get_git_version
36+
from .crypto import sha256
3637

3738
if TYPE_CHECKING:
3839
from .network import ProxySettings
@@ -140,6 +141,17 @@ def get_traceback_info(
140141
"id": _id,
141142
}
142143

144+
@classmethod
145+
def get_traceback_groupid_hash(
146+
cls,
147+
exctype: type[BaseException],
148+
excvalue: BaseException,
149+
tb: TracebackType | None,
150+
) -> bytes:
151+
tb_info = cls.get_traceback_info(exctype, excvalue, tb)
152+
_id = tb_info["id"]
153+
return sha256(str(_id))
154+
143155
def get_additional_info(self):
144156
args = {
145157
"app_version": get_git_version() or ELECTRUM_VERSION,

electrum/gui/qml/qeapp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ def __init__(self, *, slot):
537537
Logger.__init__(self)
538538
assert self._INSTANCE is None, "Exception_Hook is supposed to be a singleton"
539539
self.wallet_types_seen = set() # type: Set[str]
540+
self.exception_ids_seen = set() # type: Set[bytes]
540541

541542
sys.excepthook = self.handler
542543
threading.excepthook = self.handler
@@ -554,4 +555,8 @@ def maybe_setup(cls, *, wallet: 'Abstract_Wallet' = None, slot=None) -> None:
554555

555556
def handler(self, *exc_info):
556557
self.logger.error('exception caught by crash reporter', exc_info=exc_info)
558+
groupid_hash = BaseCrashReporter.get_traceback_groupid_hash(*exc_info)
559+
if groupid_hash in self.exception_ids_seen:
560+
return # to avoid annoying the user, only show crash reporter once per exception groupid
561+
self.exception_ids_seen.add(groupid_hash)
557562
self._report_exception.emit(*exc_info)

electrum/gui/qt/exception_window.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def __init__(self, *, config: 'SimpleConfig'):
177177
assert self._INSTANCE is None, "Exception_Hook is supposed to be a singleton"
178178
self.config = config
179179
self.wallet_types_seen = set() # type: Set[str]
180+
self.exception_ids_seen = set() # type: Set[bytes]
180181

181182
sys.excepthook = self.handler
182183
self._report_exception.connect(_show_window)
@@ -191,6 +192,10 @@ def maybe_setup(cls, *, config: 'SimpleConfig', wallet: 'Abstract_Wallet' = None
191192

192193
def handler(self, *exc_info):
193194
self.logger.error('exception caught by crash reporter', exc_info=exc_info)
195+
groupid_hash = BaseCrashReporter.get_traceback_groupid_hash(*exc_info)
196+
if groupid_hash in self.exception_ids_seen:
197+
return # to avoid annoying the user, only show crash reporter once per exception groupid
198+
self.exception_ids_seen.add(groupid_hash)
194199
self._report_exception.emit(self.config, *exc_info)
195200

196201

0 commit comments

Comments
 (0)