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:
parent
f8ca1d122d
commit
05fb67d409
@ -699,7 +699,11 @@ to a cloze type first, via 'Notes>Change Note Type'"""
|
||||
self.parentWindow.activateWindow()
|
||||
|
||||
def addMedia(self, path, canDelete=False):
|
||||
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):
|
||||
|
@ -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<io::Error> for AnkiError {
|
||||
|
||||
impl From<rusqlite::Error> 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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user