From a53c1301772d225b91db815b1c29e0437849598f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 2 Jun 2021 11:04:53 +1000 Subject: [PATCH] close Anki after a panic occurs Once the mutex has been poisoned the app is unusable, and users were struggling to close it. This also ensures we'll receive the original error report, instead of the follow-up poison errors that don't tell us what caused the issue. https://forums.ankiweb.net/t/error-message-keeps-popping-up/10494 --- qt/aqt/errors.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/qt/aqt/errors.py b/qt/aqt/errors.py index 4cedf31d0..6150b47fb 100644 --- a/qt/aqt/errors.py +++ b/qt/aqt/errors.py @@ -93,7 +93,14 @@ class ErrorHandler(QObject): showWarning(markdown(tr.errors_accessing_db())) return - if self.mw.addonManager.dirty: + must_close = False + if "PanicException" in error: + must_close = True + txt = markdown( + "**A fatal error occurred, and Anki must close. Please report this message on the forums.**" + ) + error = f"{supportText() + self._addonText(error)}\n{error}" + elif self.mw.addonManager.dirty: txt = markdown(tr.errors_addons_active_popup()) error = f"{supportText() + self._addonText(error)}\n{error}" else: @@ -103,6 +110,8 @@ class ErrorHandler(QObject): # show dialog txt = f"{txt}
{error}
" showText(txt, type="html", copyBtn=True) + if must_close: + sys.exit(1) def _addonText(self, error: str) -> str: matches = re.findall(r"addons21/(.*?)/", error)