From 328c73d0bc638c2d093fbc1166fed5a9ecf177dc Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 15 Dec 2018 13:14:33 +1000 Subject: [PATCH] ignore broken reset hooks in database check ideally the original code should be correctly cleaning up the hooks, but if it does not, then we don't want to repeatedly present the user with confusing errors when they try to check their database is ok. --- anki/hooks.py | 12 ++++++++++-- aqt/main.py | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/anki/hooks.py b/anki/hooks.py index 78b613402..622112c0b 100644 --- a/anki/hooks.py +++ b/anki/hooks.py @@ -25,13 +25,21 @@ def runHook(hook, *args): hook = _hooks.get(hook, None) if hook: for func in hook: - func(*args) + try: + func(*args) + except: + hook.remove(func) + raise def runFilter(hook, arg, *args): hook = _hooks.get(hook, None) if hook: for func in hook: - arg = func(arg, *args) + try: + arg = func(arg, *args) + except: + hook.remove(func) + raise return arg def addHook(hook, func): diff --git a/aqt/main.py b/aqt/main.py index ad46177d0..a3882fb6b 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -1054,7 +1054,17 @@ will be lost. Continue?""")) showText(ret) else: tooltip(ret) - self.reset() + + # if an error has directed the user to check the database, + # silently clean up any broken reset hooks which distract from + # the underlying issue + while True: + try: + self.reset() + break + except Exception as e: + print("swallowed exception in reset hook:", e) + continue return ret def onCheckMediaDB(self):