From c329759a88ef7cc51a753dad7d7ba0526d6c91be Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 4 Feb 2020 15:16:11 +1000 Subject: [PATCH] catch DB errors in sync --- qt/aqt/mediasync.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/qt/aqt/mediasync.py b/qt/aqt/mediasync.py index 1a57589ac..b56c8bb7e 100644 --- a/qt/aqt/mediasync.py +++ b/qt/aqt/mediasync.py @@ -15,6 +15,7 @@ from anki.lang import _ from anki.media import media_paths_from_col_path from anki.rsbackend import ( AnkiWebAuthFailed, + DBError, Interrupted, MediaSyncDownloadedChanges, MediaSyncDownloadedFiles, @@ -117,7 +118,9 @@ class MediaSyncer: (media_folder, media_db) = media_paths_from_col_path(self.mw.col.path) def run() -> None: - self.mw.col.backend.sync_media(hkey, media_folder, media_db, self._endpoint()) + self.mw.col.backend.sync_media( + hkey, media_folder, media_db, self._endpoint() + ) self.mw.taskman.run_in_background(run, self._on_finished) @@ -147,19 +150,22 @@ class MediaSyncer: self._log_and_notify(_("Media sync complete.")) def _handle_sync_error(self, exc: BaseException): + if isinstance(exc, Interrupted): + self._log_and_notify(_("Media sync aborted.")) + return + + self._log_and_notify(_("Media sync failed.")) if isinstance(exc, AnkiWebAuthFailed): self.mw.pm.set_sync_key(None) - self._log_and_notify(_("Authentication failed.")) showWarning(_("AnkiWeb ID or password was incorrect; please try again.")) - elif isinstance(exc, Interrupted): - self._log_and_notify(_("Media sync aborted.")) elif isinstance(exc, NetworkError): - self._log_and_notify(_("Network error.")) showWarning( _("Syncing failed; please check your internet connection.") + "\n\n" + _("Detailed error: {}").format(str(exc)) ) + elif isinstance(exc, DBError): + showWarning(_("Problem accessing the media database: {}").format(str(exc))) else: raise exc