From 65b8988817009c1f2506292ee5d21ef6ab696eb7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 26 Mar 2020 09:53:15 +1000 Subject: [PATCH] reduce the chances of add-ons preventing collections from loading https://anki.tenderapp.com/discussions/ankidesktop/39953-sync-fail-with-images#comment_48182205 --- qt/aqt/main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 7e84f59aa..03d89c6f8 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -442,7 +442,7 @@ close the profile or restart Anki.""" def loadCollection(self) -> bool: try: - return self._loadCollection() + self._loadCollection() except Exception as e: showWarning( tr(TR.ERRORS_UNABLE_OPEN_COLLECTION) + "\n" + traceback.format_exc() @@ -460,15 +460,22 @@ close the profile or restart Anki.""" self.showProfileManager() return False - def _loadCollection(self) -> bool: + # make sure we don't get into an inconsistent state if an add-on + # has broken the deck browser or the did_load hook + try: + self.maybeEnableUndo() + gui_hooks.collection_did_load(self.col) + self.moveToState("deckBrowser") + except Exception as e: + # dump error to stderr so it gets picked up by errors.py + traceback.print_exc() + + return True + + def _loadCollection(self): cpath = self.pm.collectionPath() self.col = Collection(cpath, backend=self.backend) - self.setEnabled(True) - self.maybeEnableUndo() - gui_hooks.collection_did_load(self.col) - self.moveToState("deckBrowser") - return True def reopen(self): cpath = self.pm.collectionPath()