add separate json error

This commit is contained in:
Damien Elmes 2020-04-06 16:29:31 +10:00
parent 03db16460a
commit 75faba1667
3 changed files with 8 additions and 1 deletions

View file

@ -131,6 +131,7 @@ message BackendError {
SyncError sync_error = 7; SyncError sync_error = 7;
// user interrupted operation // user interrupted operation
Empty interrupted = 8; Empty interrupted = 8;
string json_error = 9;
} }
} }

View file

@ -76,6 +76,7 @@ fn anki_error_to_proto_error(err: AnkiError, i18n: &I18n) -> pb::BackendError {
AnkiError::CollectionNotOpen => V::InvalidInput(pb::Empty {}), AnkiError::CollectionNotOpen => V::InvalidInput(pb::Empty {}),
AnkiError::CollectionAlreadyOpen => V::InvalidInput(pb::Empty {}), AnkiError::CollectionAlreadyOpen => V::InvalidInput(pb::Empty {}),
AnkiError::SchemaChange => V::InvalidInput(pb::Empty {}), AnkiError::SchemaChange => V::InvalidInput(pb::Empty {}),
AnkiError::JSONError { info } => V::JsonError(info),
}; };
pb::BackendError { pb::BackendError {

View file

@ -31,6 +31,9 @@ pub enum AnkiError {
#[fail(display = "Sync error: {:?}, {}", kind, info)] #[fail(display = "Sync error: {:?}, {}", kind, info)]
SyncError { info: String, kind: SyncErrorKind }, SyncError { info: String, kind: SyncErrorKind },
#[fail(display = "JSON encode/decode error: {}", info)]
JSONError { info: String },
#[fail(display = "The user interrupted the operation.")] #[fail(display = "The user interrupted the operation.")]
Interrupted, Interrupted,
@ -223,7 +226,9 @@ impl From<zip::result::ZipError> for AnkiError {
impl From<serde_json::Error> for AnkiError { impl From<serde_json::Error> for AnkiError {
fn from(err: serde_json::Error) -> Self { fn from(err: serde_json::Error) -> Self {
AnkiError::sync_misc(err.to_string()) AnkiError::JSONError {
info: err.to_string(),
}
} }
} }