mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
improve geosearch error messages
This commit is contained in:
parent
312515dd6b
commit
3cb1f6d0a1
3 changed files with 200 additions and 19 deletions
|
@ -60,7 +60,7 @@ pub enum UserError {
|
|||
DocumentLimitReached,
|
||||
InvalidDocumentId { document_id: Value },
|
||||
InvalidFacetsDistribution { invalid_facets_name: BTreeSet<String> },
|
||||
InvalidGeoField { document_id: Value },
|
||||
InvalidGeoField(GeoError),
|
||||
InvalidFilter(String),
|
||||
InvalidSortableAttribute { field: String, valid_fields: BTreeSet<String> },
|
||||
SortRankingRuleMissing,
|
||||
|
@ -76,6 +76,14 @@ pub enum UserError {
|
|||
InvalidMinTypoWordLenSetting(u8, u8),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum GeoError {
|
||||
MissingLatitude { document_id: Value },
|
||||
MissingLongitude { document_id: Value },
|
||||
BadLatitude { document_id: Value, value: Value },
|
||||
BadLongitude { document_id: Value, value: Value },
|
||||
}
|
||||
|
||||
impl From<io::Error> for Error {
|
||||
fn from(error: io::Error) -> Error {
|
||||
// TODO must be improved and more precise
|
||||
|
@ -230,17 +238,7 @@ impl fmt::Display for UserError {
|
|||
name_list
|
||||
)
|
||||
}
|
||||
Self::InvalidGeoField { document_id } => {
|
||||
let document_id = match document_id {
|
||||
Value::String(id) => id.clone(),
|
||||
_ => document_id.to_string(),
|
||||
};
|
||||
write!(
|
||||
f,
|
||||
"The document with the id: `{}` contains an invalid `_geo` field.",
|
||||
document_id
|
||||
)
|
||||
},
|
||||
Self::InvalidGeoField(error) => write!(f, "{error}"),
|
||||
Self::InvalidDocumentId { document_id } => {
|
||||
let document_id = match document_id {
|
||||
Value::String(id) => id.clone(),
|
||||
|
@ -314,6 +312,33 @@ impl fmt::Display for FieldIdMapMissingEntry {
|
|||
|
||||
impl StdError for FieldIdMapMissingEntry {}
|
||||
|
||||
impl From<GeoError> for UserError {
|
||||
fn from(geo_error: GeoError) -> Self {
|
||||
UserError::InvalidGeoField(geo_error)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for GeoError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
GeoError::MissingLatitude { document_id } => {
|
||||
write!(f, "Could not find latitude in the document with the id: `{document_id}`. Was expecting a `_geo.lat` field.")
|
||||
}
|
||||
GeoError::MissingLongitude { document_id } => {
|
||||
write!(f, "Could not find longitude in the document with the id: `{document_id}`. Was expecting a `_geo.lng` field.")
|
||||
}
|
||||
GeoError::BadLatitude { document_id, value } => {
|
||||
write!(f, "Could not parse latitude in the document with the id: `{document_id}`. Was expecting a number but instead got `{value}`.")
|
||||
}
|
||||
GeoError::BadLongitude { document_id, value } => {
|
||||
write!(f, "Could not parse longitude in the document with the id: `{document_id}`. Was expecting a number but instead got `{value}`.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StdError for GeoError {}
|
||||
|
||||
impl fmt::Display for SerializationError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue