mirror of
https://github.com/ankitects/anki.git
synced 2025-12-11 13:56:55 -05:00
tuple type for InvalidInput
This commit is contained in:
parent
a250464309
commit
2b6c8b4296
3 changed files with 13 additions and 16 deletions
|
|
@ -204,18 +204,14 @@ impl Note {
|
||||||
impl Collection {
|
impl Collection {
|
||||||
pub fn browser_row_for_id(&mut self, id: i64) -> Result<Row> {
|
pub fn browser_row_for_id(&mut self, id: i64) -> Result<Row> {
|
||||||
if self.get_bool(BoolKey::BrowserTableShowNotesMode) {
|
if self.get_bool(BoolKey::BrowserTableShowNotesMode) {
|
||||||
let columns =
|
let columns = self
|
||||||
self.get_desktop_browser_note_columns()
|
.get_desktop_browser_note_columns()
|
||||||
.ok_or(AnkiError::InvalidInput {
|
.ok_or(AnkiError::invalid_input("Note columns not set."))?;
|
||||||
info: "Note columns not set.".into(),
|
|
||||||
})?;
|
|
||||||
NoteRowContext::new(self, id)?.browser_row_for_id(&columns)
|
NoteRowContext::new(self, id)?.browser_row_for_id(&columns)
|
||||||
} else {
|
} else {
|
||||||
let columns =
|
let columns = self
|
||||||
self.get_desktop_browser_card_columns()
|
.get_desktop_browser_card_columns()
|
||||||
.ok_or(AnkiError::InvalidInput {
|
.ok_or(AnkiError::invalid_input("Card columns not set."))?;
|
||||||
info: "Card columns not set.".into(),
|
|
||||||
})?;
|
|
||||||
CardRowContext::new(self, id, card_render_required(&columns))?
|
CardRowContext::new(self, id, card_render_required(&columns))?
|
||||||
.browser_row_for_id(&columns)
|
.browser_row_for_id(&columns)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum AnkiError {
|
pub enum AnkiError {
|
||||||
InvalidInput { info: String },
|
InvalidInput(String),
|
||||||
TemplateError { info: String },
|
TemplateError { info: String },
|
||||||
TemplateSaveError { ordinal: usize },
|
TemplateSaveError { ordinal: usize },
|
||||||
IoError { info: String },
|
IoError { info: String },
|
||||||
|
|
@ -49,7 +49,7 @@ impl Display for AnkiError {
|
||||||
// error helpers
|
// error helpers
|
||||||
impl AnkiError {
|
impl AnkiError {
|
||||||
pub(crate) fn invalid_input<S: Into<String>>(s: S) -> AnkiError {
|
pub(crate) fn invalid_input<S: Into<String>>(s: S) -> AnkiError {
|
||||||
AnkiError::InvalidInput { info: s.into() }
|
AnkiError::InvalidInput(s.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn localized_description(&self, tr: &I18n) -> String {
|
pub fn localized_description(&self, tr: &I18n) -> String {
|
||||||
|
|
@ -65,7 +65,7 @@ impl AnkiError {
|
||||||
.into(),
|
.into(),
|
||||||
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) => {
|
||||||
if info.is_empty() {
|
if info.is_empty() {
|
||||||
tr.errors_invalid_input_empty().into()
|
tr.errors_invalid_input_empty().into()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -211,9 +211,10 @@ fn write_order(sql: &mut String, items: SearchItems, kind: SortKind, reverse: bo
|
||||||
SearchItems::Notes => note_order_from_sortkind(kind),
|
SearchItems::Notes => note_order_from_sortkind(kind),
|
||||||
};
|
};
|
||||||
if order.is_empty() {
|
if order.is_empty() {
|
||||||
return Err(AnkiError::InvalidInput {
|
return Err(AnkiError::invalid_input(format!(
|
||||||
info: format!("Can't sort {:?} by {:?}.", items, kind),
|
"Can't sort {:?} by {:?}.",
|
||||||
});
|
items, kind
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
if reverse {
|
if reverse {
|
||||||
sql.push_str(
|
sql.push_str(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue