From fa19f590e8cb4ac57720d1e69b58c4da4b952196 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Tue, 25 May 2021 21:01:03 +0200 Subject: [PATCH] Add details to TemplateSaveError --- ftl/core/card-templates.ftl | 1 + rslib/src/error/mod.rs | 17 ++++++++++++++--- rslib/src/notetype/mod.rs | 3 ++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ftl/core/card-templates.ftl b/ftl/core/card-templates.ftl index 544d6d3bd..6b0d8a1ef 100644 --- a/ftl/core/card-templates.ftl +++ b/ftl/core/card-templates.ftl @@ -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... diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index 400a2a602..e623d94e2 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -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!("{}
{}", 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 for AnkiError { pub struct TemplateSaveError { pub notetype: String, pub ordinal: usize, + pub details: TemplateSaveErrorDetails, +} + +#[derive(Debug, PartialEq)] +pub enum TemplateSaveErrorDetails { + TemplateError, } diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index 052b3ddda..924de46e1 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -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);