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