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()