add some error messages

This commit is contained in:
Tamo 2021-10-22 19:00:33 +02:00
parent c8d03046bf
commit 1327807caa
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69

View File

@ -29,7 +29,18 @@ impl<'a> From<VerboseError<Span<'a>>> for Error {
} }
fn parse<T: FromStr>(tok: &Token) -> Result<T> { fn parse<T: FromStr>(tok: &Token) -> Result<T> {
Ok(tok.inner.parse().ok().unwrap()) match tok.inner.parse::<T>() {
Ok(t) => Ok(t),
Err(_e) => Err(UserError::InvalidFilter {
input: format!(
"Could not parse `{}` at line {} and offset {}",
tok.inner,
tok.position.location_line(),
tok.position.get_column()
),
}
.into()),
}
} }
impl<'a> Filter<'a> { impl<'a> Filter<'a> {
@ -291,10 +302,28 @@ impl<'a> Filter<'a> {
if let Some(fid) = filterable_fields.id(&fid.inner.to_lowercase()) { if let Some(fid) = filterable_fields.id(&fid.inner.to_lowercase()) {
Self::evaluate_operator(rtxn, index, numbers_db, strings_db, fid, &op) Self::evaluate_operator(rtxn, index, numbers_db, strings_db, fid, &op)
} else { } else {
// TODO TAMO: update the error message match fid.inner {
return Err(UserError::InvalidFilter { // TODO update the error messages according to the spec
input: format!("Bad filter, available filters are {:?}", filterable_fields), "_geo" => {
})?; return Err(UserError::InvalidFilter { input: format!("Tried to use _geo in a filter, you probably wanted to use _geoRadius(latitude, longitude, radius)") })?;
}
"_geoDistance" => {
return Err(UserError::InvalidFilter {
input: format!("Reserved field _geoDistance"),
})?;
}
fid if fid.starts_with("_geoPoint(") => {
return Err(UserError::InvalidFilter { input: format!("_geoPoint only available in sort. You wanted to use _geoRadius") })?;
}
fid => {
return Err(UserError::InvalidFilter {
input: format!(
"Bad filter {}, available filters are {:?}",
fid, filterable_fields
),
})?;
}
}
} }
} }
FilterCondition::Or(lhs, rhs) => { FilterCondition::Or(lhs, rhs) => {