mirror of
https://github.com/ankitects/anki.git
synced 2025-12-10 21:36:55 -05:00
clearer message when template error is preventing save
This commit is contained in:
parent
b6687f0203
commit
7e7f2d0be4
5 changed files with 14 additions and 5 deletions
|
|
@ -747,7 +747,7 @@ Enter deck to place new %s cards in, or leave blank:"""
|
|||
try:
|
||||
fut.result()
|
||||
except TemplateError as e:
|
||||
showWarning("Unable to save changes: " + str(e))
|
||||
showWarning(str(e))
|
||||
return
|
||||
self.mw.reset()
|
||||
tooltip("Changes saved.", parent=self.parent())
|
||||
|
|
|
|||
|
|
@ -13,3 +13,6 @@ card-templates-preview-box = Preview
|
|||
card-templates-template-box = Template
|
||||
card-templates-sample-cloze = This is a {"{{c1::"}sample{"}}"} cloze deletion.
|
||||
card-templates-fill-empty = Fill Empty Fields
|
||||
card-templates-invalid-template-number = Please correct the problems on card template { $number } first.
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ fn anki_error_to_proto_error(err: AnkiError, i18n: &I18n) -> pb::BackendError {
|
|||
AnkiError::Existing => V::Exists(Empty {}),
|
||||
AnkiError::DeckIsFiltered => V::DeckIsFiltered(Empty {}),
|
||||
AnkiError::SearchError(_) => V::InvalidInput(pb::Empty {}),
|
||||
AnkiError::TemplateSaveError { .. } => V::TemplateParse(pb::Empty {}),
|
||||
};
|
||||
|
||||
pb::BackendError {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright: Ankitects Pty Ltd and contributors
|
||||
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||
|
||||
use crate::i18n::{tr_strs, I18n, TR};
|
||||
use crate::i18n::{tr_args, tr_strs, I18n, TR};
|
||||
pub use failure::{Error, Fail};
|
||||
use reqwest::StatusCode;
|
||||
use std::io;
|
||||
|
|
@ -16,6 +16,9 @@ pub enum AnkiError {
|
|||
#[fail(display = "invalid card template: {}", info)]
|
||||
TemplateError { info: String },
|
||||
|
||||
#[fail(display = "unable to save template {}", ordinal)]
|
||||
TemplateSaveError { ordinal: usize },
|
||||
|
||||
#[fail(display = "I/O error: {}", info)]
|
||||
IOError { info: String },
|
||||
|
||||
|
|
@ -107,6 +110,10 @@ impl AnkiError {
|
|||
// already localized
|
||||
info.into()
|
||||
}
|
||||
AnkiError::TemplateSaveError { ordinal } => i18n.trn(
|
||||
TR::CardTemplatesInvalidTemplateNumber,
|
||||
tr_args!["number"=>ordinal+1],
|
||||
),
|
||||
AnkiError::DBError { info, kind } => match kind {
|
||||
DBErrorKind::Corrupt => info.clone(),
|
||||
DBErrorKind::Locked => "Anki already open, or media currently syncing.".into(),
|
||||
|
|
|
|||
|
|
@ -229,9 +229,7 @@ impl NoteType {
|
|||
}
|
||||
});
|
||||
if let Some(idx) = invalid_card_idx {
|
||||
return Err(AnkiError::TemplateError {
|
||||
info: format!("invalid card {}", idx + 1),
|
||||
});
|
||||
return Err(AnkiError::TemplateSaveError { ordinal: idx });
|
||||
}
|
||||
let reqs = self.updated_requirements(&parsed_templates);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue