diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 37f95d47b..2fb11c973 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -699,7 +699,11 @@ to a cloze type first, via 'Notes>Change Note Type'""" self.parentWindow.activateWindow() def addMedia(self, path, canDelete=False): - html = self._addMedia(path, canDelete) + try: + html = self._addMedia(path, canDelete) + except Exception as e: + showWarning(str(e)) + return self.web.eval("insertHtmlRemovingInitialBR(%s);" % json.dumps(html)) def _addMedia(self, path, canDelete=False): diff --git a/rslib/src/err.rs b/rslib/src/err.rs index 796aa48e3..caee450c5 100644 --- a/rslib/src/err.rs +++ b/rslib/src/err.rs @@ -110,6 +110,7 @@ impl AnkiError { } AnkiError::DBError { info, kind } => match kind { DBErrorKind::Corrupt => info.clone(), + DBErrorKind::Locked => "Anki already open, or media currently syncing.".into(), _ => format!("{:?}", self), }, AnkiError::SearchError(details) => { @@ -148,7 +149,13 @@ impl From for AnkiError { impl From for AnkiError { fn from(err: rusqlite::Error) -> Self { - if let rusqlite::Error::SqliteFailure(_error, Some(reason)) = &err { + if let rusqlite::Error::SqliteFailure(error, Some(reason)) = &err { + if error.code == rusqlite::ErrorCode::DatabaseBusy { + return AnkiError::DBError { + info: "".to_string(), + kind: DBErrorKind::Locked, + }; + } if reason.contains("regex parse error") { return AnkiError::SearchError(Some(reason.to_owned())); } @@ -290,5 +297,6 @@ pub enum DBErrorKind { FileTooOld, MissingEntity, Corrupt, + Locked, Other, }