mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
convert Json and Proto errors to tuple
This commit is contained in:
parent
55a6f10d24
commit
7a29d987c4
3 changed files with 10 additions and 16 deletions
|
@ -25,8 +25,8 @@ pub(super) fn anki_error_to_proto_error(err: AnkiError, tr: &I18n) -> pb::Backen
|
|||
AnkiError::Interrupted => V::Interrupted(pb::Empty {}),
|
||||
AnkiError::CollectionNotOpen => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::CollectionAlreadyOpen => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::JsonError { info } => V::JsonError(info),
|
||||
AnkiError::ProtoError { info } => V::ProtoError(info),
|
||||
AnkiError::JsonError(info) => V::JsonError(info),
|
||||
AnkiError::ProtoError(info) => V::ProtoError(info),
|
||||
AnkiError::NotFound => V::NotFoundError(pb::Empty {}),
|
||||
AnkiError::Existing => V::Exists(pb::Empty {}),
|
||||
AnkiError::DeckIsFiltered => V::DeckIsFiltered(pb::Empty {}),
|
||||
|
|
|
@ -20,14 +20,14 @@ pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
|||
#[derive(Debug, PartialEq)]
|
||||
pub enum AnkiError {
|
||||
InvalidInput(String),
|
||||
TemplateError { info: String },
|
||||
TemplateError(String),
|
||||
TemplateSaveError { ordinal: usize },
|
||||
IoError(String),
|
||||
DbError(DbError),
|
||||
NetworkError(NetworkError),
|
||||
SyncError(SyncError),
|
||||
JsonError { info: String },
|
||||
ProtoError { info: String },
|
||||
JsonError(String),
|
||||
ProtoError(String),
|
||||
ParseNumError,
|
||||
Interrupted,
|
||||
CollectionNotOpen,
|
||||
|
@ -56,7 +56,7 @@ impl AnkiError {
|
|||
match self {
|
||||
AnkiError::SyncError(err) => err.localized_description(tr),
|
||||
AnkiError::NetworkError(err) => err.localized_description(tr),
|
||||
AnkiError::TemplateError { info } => {
|
||||
AnkiError::TemplateError(info) => {
|
||||
// already localized
|
||||
info.into()
|
||||
}
|
||||
|
@ -102,25 +102,19 @@ impl From<io::Error> for AnkiError {
|
|||
|
||||
impl From<serde_json::Error> for AnkiError {
|
||||
fn from(err: serde_json::Error) -> Self {
|
||||
AnkiError::JsonError {
|
||||
info: err.to_string(),
|
||||
}
|
||||
AnkiError::JsonError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<prost::EncodeError> for AnkiError {
|
||||
fn from(err: prost::EncodeError) -> Self {
|
||||
AnkiError::ProtoError {
|
||||
info: err.to_string(),
|
||||
}
|
||||
AnkiError::ProtoError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<prost::DecodeError> for AnkiError {
|
||||
fn from(err: prost::DecodeError) -> Self {
|
||||
AnkiError::ProtoError {
|
||||
info: err.to_string(),
|
||||
}
|
||||
AnkiError::ProtoError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ fn template_error_to_anki_error(err: TemplateError, q_side: bool, tr: &I18n) ->
|
|||
header, details, TEMPLATE_ERROR_LINK, more_info
|
||||
);
|
||||
|
||||
AnkiError::TemplateError { info }
|
||||
AnkiError::TemplateError(info)
|
||||
}
|
||||
|
||||
fn localized_template_error(tr: &I18n, err: TemplateError) -> String {
|
||||
|
|
Loading…
Reference in a new issue