show clearer error when media db locked

should not happen frequently during a sync, but may happen during
the initial change checking stage

https://forums.ankiweb.net/t/error-when-adding-audio-file/495/2
This commit is contained in:
Damien Elmes 2020-07-01 11:19:06 +10:00
parent f8ca1d122d
commit 05fb67d409
2 changed files with 14 additions and 2 deletions

View File

@ -699,7 +699,11 @@ to a cloze type first, via 'Notes>Change Note Type'"""
self.parentWindow.activateWindow() self.parentWindow.activateWindow()
def addMedia(self, path, canDelete=False): 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)) self.web.eval("insertHtmlRemovingInitialBR(%s);" % json.dumps(html))
def _addMedia(self, path, canDelete=False): def _addMedia(self, path, canDelete=False):

View File

@ -110,6 +110,7 @@ impl AnkiError {
} }
AnkiError::DBError { info, kind } => match kind { AnkiError::DBError { info, kind } => match kind {
DBErrorKind::Corrupt => info.clone(), DBErrorKind::Corrupt => info.clone(),
DBErrorKind::Locked => "Anki already open, or media currently syncing.".into(),
_ => format!("{:?}", self), _ => format!("{:?}", self),
}, },
AnkiError::SearchError(details) => { AnkiError::SearchError(details) => {
@ -148,7 +149,13 @@ impl From<io::Error> for AnkiError {
impl From<rusqlite::Error> for AnkiError { impl From<rusqlite::Error> for AnkiError {
fn from(err: rusqlite::Error) -> Self { 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") { if reason.contains("regex parse error") {
return AnkiError::SearchError(Some(reason.to_owned())); return AnkiError::SearchError(Some(reason.to_owned()));
} }
@ -290,5 +297,6 @@ pub enum DBErrorKind {
FileTooOld, FileTooOld,
MissingEntity, MissingEntity,
Corrupt, Corrupt,
Locked,
Other, Other,
} }