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 {
|
||||
pub fn browser_row_for_id(&mut self, id: i64) -> Result<Row> {
|
||||
if self.get_bool(BoolKey::BrowserTableShowNotesMode) {
|
||||
let columns =
|
||||
self.get_desktop_browser_note_columns()
|
||||
.ok_or(AnkiError::InvalidInput {
|
||||
info: "Note columns not set.".into(),
|
||||
})?;
|
||||
let columns = self
|
||||
.get_desktop_browser_note_columns()
|
||||
.ok_or(AnkiError::invalid_input("Note columns not set."))?;
|
||||
NoteRowContext::new(self, id)?.browser_row_for_id(&columns)
|
||||
} else {
|
||||
let columns =
|
||||
self.get_desktop_browser_card_columns()
|
||||
.ok_or(AnkiError::InvalidInput {
|
||||
info: "Card columns not set.".into(),
|
||||
})?;
|
||||
let columns = self
|
||||
.get_desktop_browser_card_columns()
|
||||
.ok_or(AnkiError::invalid_input("Card columns not set."))?;
|
||||
CardRowContext::new(self, id, card_render_required(&columns))?
|
||||
.browser_row_for_id(&columns)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub type Result<T, E = AnkiError> = std::result::Result<T, E>;
|
|||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum AnkiError {
|
||||
InvalidInput { info: String },
|
||||
InvalidInput(String),
|
||||
TemplateError { info: String },
|
||||
TemplateSaveError { ordinal: usize },
|
||||
IoError { info: String },
|
||||
|
|
@ -49,7 +49,7 @@ impl Display for AnkiError {
|
|||
// error helpers
|
||||
impl 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 {
|
||||
|
|
@ -65,7 +65,7 @@ impl AnkiError {
|
|||
.into(),
|
||||
AnkiError::DbError(err) => err.localized_description(tr),
|
||||
AnkiError::SearchError(kind) => kind.localized_description(&tr),
|
||||
AnkiError::InvalidInput { info } => {
|
||||
AnkiError::InvalidInput(info) => {
|
||||
if info.is_empty() {
|
||||
tr.errors_invalid_input_empty().into()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -211,9 +211,10 @@ fn write_order(sql: &mut String, items: SearchItems, kind: SortKind, reverse: bo
|
|||
SearchItems::Notes => note_order_from_sortkind(kind),
|
||||
};
|
||||
if order.is_empty() {
|
||||
return Err(AnkiError::InvalidInput {
|
||||
info: format!("Can't sort {:?} by {:?}.", items, kind),
|
||||
});
|
||||
return Err(AnkiError::invalid_input(format!(
|
||||
"Can't sort {:?} by {:?}.",
|
||||
items, kind
|
||||
)));
|
||||
}
|
||||
if reverse {
|
||||
sql.push_str(
|
||||
|
|
|
|||
Loading…
Reference in a new issue