Add details to TemplateSaveError

This commit is contained in:
RumovZ 2021-05-25 21:01:03 +02:00
parent db9594818a
commit fa19f590e8
3 changed files with 17 additions and 4 deletions

View File

@ -21,6 +21,7 @@ card-templates-night-mode = Night Mode
card-templates-add-mobile-class = Add Mobile Class
card-templates-preview-settings = Options
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-discard-changes = Discard changes?
card-templates-add-card-type = Add Card Type...

View File

@ -61,9 +61,14 @@ impl AnkiError {
// already localized
info.into()
}
AnkiError::TemplateSaveError(err) => tr
.card_templates_invalid_template_number(err.ordinal + 1, &err.notetype)
.into(),
AnkiError::TemplateSaveError(err) => {
let header =
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::SearchError(kind) => kind.localized_description(&tr),
AnkiError::InvalidInput(info) => {
@ -135,4 +140,10 @@ impl From<regex::Error> for AnkiError {
pub struct TemplateSaveError {
pub notetype: String,
pub ordinal: usize,
pub details: TemplateSaveErrorDetails,
}
#[derive(Debug, PartialEq)]
pub enum TemplateSaveErrorDetails {
TemplateError,
}

View File

@ -37,7 +37,7 @@ pub use crate::backend_proto::{
};
use crate::{
define_newtype,
error::TemplateSaveError,
error::{TemplateSaveError, TemplateSaveErrorDetails},
prelude::*,
template::{FieldRequirements, ParsedTemplate},
text::ensure_string_in_nfc,
@ -330,6 +330,7 @@ impl Notetype {
return Err(AnkiError::TemplateSaveError(TemplateSaveError {
notetype: self.name.clone(),
ordinal: idx,
details: TemplateSaveErrorDetails::TemplateError,
}));
}
let reqs = self.updated_requirements(&parsed_templates);