Add details to TemplateSaveError
This commit is contained in:
parent
db9594818a
commit
fa19f590e8
@ -21,6 +21,7 @@ card-templates-night-mode = Night Mode
|
|||||||
card-templates-add-mobile-class = Add Mobile Class
|
card-templates-add-mobile-class = Add Mobile Class
|
||||||
card-templates-preview-settings = Options
|
card-templates-preview-settings = Options
|
||||||
card-templates-invalid-template-number = Card template { $number } in notetype '{ $notetype }' has a problem.
|
card-templates-invalid-template-number = Card template { $number } in notetype '{ $notetype }' has a problem.
|
||||||
|
card-templates-see-preview = See the render preview for more information.
|
||||||
card-templates-changes-saved = Changes saved.
|
card-templates-changes-saved = Changes saved.
|
||||||
card-templates-discard-changes = Discard changes?
|
card-templates-discard-changes = Discard changes?
|
||||||
card-templates-add-card-type = Add Card Type...
|
card-templates-add-card-type = Add Card Type...
|
||||||
|
@ -61,9 +61,14 @@ impl AnkiError {
|
|||||||
// already localized
|
// already localized
|
||||||
info.into()
|
info.into()
|
||||||
}
|
}
|
||||||
AnkiError::TemplateSaveError(err) => tr
|
AnkiError::TemplateSaveError(err) => {
|
||||||
.card_templates_invalid_template_number(err.ordinal + 1, &err.notetype)
|
let header =
|
||||||
.into(),
|
tr.card_templates_invalid_template_number(err.ordinal + 1, &err.notetype);
|
||||||
|
let details = match err.details {
|
||||||
|
TemplateSaveErrorDetails::TemplateError => tr.card_templates_see_preview(),
|
||||||
|
};
|
||||||
|
format!("{}<br>{}", header, details)
|
||||||
|
}
|
||||||
AnkiError::DbError(err) => err.localized_description(tr),
|
AnkiError::DbError(err) => err.localized_description(tr),
|
||||||
AnkiError::SearchError(kind) => kind.localized_description(&tr),
|
AnkiError::SearchError(kind) => kind.localized_description(&tr),
|
||||||
AnkiError::InvalidInput(info) => {
|
AnkiError::InvalidInput(info) => {
|
||||||
@ -135,4 +140,10 @@ impl From<regex::Error> for AnkiError {
|
|||||||
pub struct TemplateSaveError {
|
pub struct TemplateSaveError {
|
||||||
pub notetype: String,
|
pub notetype: String,
|
||||||
pub ordinal: usize,
|
pub ordinal: usize,
|
||||||
|
pub details: TemplateSaveErrorDetails,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq)]
|
||||||
|
pub enum TemplateSaveErrorDetails {
|
||||||
|
TemplateError,
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ pub use crate::backend_proto::{
|
|||||||
};
|
};
|
||||||
use crate::{
|
use crate::{
|
||||||
define_newtype,
|
define_newtype,
|
||||||
error::TemplateSaveError,
|
error::{TemplateSaveError, TemplateSaveErrorDetails},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
template::{FieldRequirements, ParsedTemplate},
|
template::{FieldRequirements, ParsedTemplate},
|
||||||
text::ensure_string_in_nfc,
|
text::ensure_string_in_nfc,
|
||||||
@ -330,6 +330,7 @@ impl Notetype {
|
|||||||
return Err(AnkiError::TemplateSaveError(TemplateSaveError {
|
return Err(AnkiError::TemplateSaveError(TemplateSaveError {
|
||||||
notetype: self.name.clone(),
|
notetype: self.name.clone(),
|
||||||
ordinal: idx,
|
ordinal: idx,
|
||||||
|
details: TemplateSaveErrorDetails::TemplateError,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
let reqs = self.updated_requirements(&parsed_templates);
|
let reqs = self.updated_requirements(&parsed_templates);
|
||||||
|
Loading…
Reference in New Issue
Block a user