Add search context for certain error kinds
This commit is contained in:
parent
5f05ca2548
commit
2a2ac38a1b
@ -129,21 +129,21 @@ impl AnkiError {
|
||||
SearchErrorKind::EmptyQuote => i18n.tr(TR::SearchEmptyQuote),
|
||||
SearchErrorKind::UnclosedQuote => i18n.tr(TR::SearchUnclosedQuote),
|
||||
SearchErrorKind::MissingKey => i18n.tr(TR::SearchMissingKey),
|
||||
SearchErrorKind::UnknownEscape(_seq) => i18n.tr(TR::SearchUnknownEscape),
|
||||
SearchErrorKind::UnknownEscape(ctx) => i18n.trn(TR::SearchUnknownEscape, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidIdList => i18n.tr(TR::SearchInvalidIdList),
|
||||
SearchErrorKind::InvalidState => i18n.tr(TR::SearchInvalidState),
|
||||
SearchErrorKind::InvalidFlag => i18n.tr(TR::SearchInvalidFlag),
|
||||
SearchErrorKind::InvalidAdded => i18n.tr(TR::SearchInvalidAdded),
|
||||
SearchErrorKind::InvalidEdited => i18n.tr(TR::SearchInvalidEdited),
|
||||
SearchErrorKind::InvalidRatedDays => i18n.tr(TR::SearchInvalidRatedDays),
|
||||
SearchErrorKind::InvalidRatedEase => i18n.tr(TR::SearchInvalidRatedEase),
|
||||
SearchErrorKind::InvalidRatedEase(ctx) => i18n.trn(TR::SearchInvalidRatedEase, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidDupeMid => i18n.tr(TR::SearchInvalidDupeMid),
|
||||
SearchErrorKind::InvalidDupeText => i18n.tr(TR::SearchInvalidDupeText),
|
||||
SearchErrorKind::InvalidPropProperty => i18n.tr(TR::SearchInvalidPropProperty),
|
||||
SearchErrorKind::InvalidPropOperator => i18n.tr(TR::SearchInvalidPropOperator),
|
||||
SearchErrorKind::InvalidPropFloat => i18n.tr(TR::SearchInvalidPropFloat),
|
||||
SearchErrorKind::InvalidPropInteger => i18n.tr(TR::SearchInvalidPropInteger),
|
||||
SearchErrorKind::InvalidPropUnsigned => i18n.tr(TR::SearchInvalidPropUnsigned),
|
||||
SearchErrorKind::InvalidPropOperator(ctx) => i18n.trn(TR::SearchInvalidPropOperator, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidPropFloat(ctx) => i18n.trn(TR::SearchInvalidPropFloat, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidPropInteger(ctx) => i18n.trn(TR::SearchInvalidPropInteger, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidPropUnsigned(ctx) => i18n.trn(TR::SearchInvalidPropUnsigned, tr_strs!["val"=>(ctx)]).into(),
|
||||
SearchErrorKind::InvalidDid => i18n.tr(TR::SearchInvalidDid),
|
||||
SearchErrorKind::InvalidMid => i18n.tr(TR::SearchInvalidMid),
|
||||
SearchErrorKind::Regex(text) => text.into(),
|
||||
@ -376,14 +376,14 @@ pub enum SearchErrorKind {
|
||||
InvalidAdded,
|
||||
InvalidEdited,
|
||||
InvalidRatedDays,
|
||||
InvalidRatedEase,
|
||||
InvalidRatedEase(String),
|
||||
InvalidDupeMid,
|
||||
InvalidDupeText,
|
||||
InvalidPropProperty,
|
||||
InvalidPropOperator,
|
||||
InvalidPropFloat,
|
||||
InvalidPropInteger,
|
||||
InvalidPropUnsigned,
|
||||
InvalidPropOperator(String),
|
||||
InvalidPropFloat(String),
|
||||
InvalidPropInteger(String),
|
||||
InvalidPropUnsigned(String),
|
||||
InvalidDid,
|
||||
InvalidMid,
|
||||
Regex(String),
|
||||
|
@ -360,19 +360,19 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||
tag("<"),
|
||||
tag(">"),
|
||||
))(tail)
|
||||
.map_err(|_| parse_failure(s, FailKind::InvalidPropOperator))?;
|
||||
.map_err(|_| parse_failure(s, FailKind::InvalidPropOperator(prop.to_string())))?;
|
||||
|
||||
let kind = if prop == "ease" {
|
||||
if let Ok(f) = num.parse::<f32>() {
|
||||
PropertyKind::Ease(f)
|
||||
} else {
|
||||
return Err(parse_failure(s, FailKind::InvalidPropFloat));
|
||||
return Err(parse_failure(s, FailKind::InvalidPropFloat(format!("{}{}", prop, operator))));
|
||||
}
|
||||
} else if prop == "due" {
|
||||
if let Ok(i) = num.parse::<i32>() {
|
||||
PropertyKind::Due(i)
|
||||
} else {
|
||||
return Err(parse_failure(s, FailKind::InvalidPropInteger));
|
||||
return Err(parse_failure(s, FailKind::InvalidPropInteger(format!("{}{}", prop, operator))));
|
||||
}
|
||||
} else if let Ok(u) = num.parse::<u32>() {
|
||||
match prop {
|
||||
@ -383,7 +383,7 @@ fn parse_prop(s: &str) -> ParseResult<SearchNode<'static>> {
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
return Err(parse_failure(s, FailKind::InvalidPropUnsigned));
|
||||
return Err(parse_failure(s, FailKind::InvalidPropUnsigned(format!("{}{}", prop, operator))));
|
||||
};
|
||||
|
||||
Ok(SearchNode::Property {
|
||||
@ -421,10 +421,10 @@ fn parse_rated(s: &str) -> ParseResult<SearchNode> {
|
||||
if u < 5 {
|
||||
Some(u)
|
||||
} else {
|
||||
return Err(parse_failure(s, FailKind::InvalidRatedEase));
|
||||
return Err(parse_failure(s, FailKind::InvalidRatedEase(days.to_string())));
|
||||
}
|
||||
} else {
|
||||
return Err(parse_failure(s, FailKind::InvalidRatedEase));
|
||||
return Err(parse_failure(s, FailKind::InvalidRatedEase(days.to_string())));
|
||||
}
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user