From a80dcfd4a3a047f98e9571231e439f7406f0beea Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 28 Sep 2021 14:32:24 +0200 Subject: [PATCH] improve error message for bad sort syntax with geosearch --- milli/src/asc_desc.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/milli/src/asc_desc.rs b/milli/src/asc_desc.rs index 5adef782f..b8323292c 100644 --- a/milli/src/asc_desc.rs +++ b/milli/src/asc_desc.rs @@ -141,6 +141,7 @@ impl FromStr for AscDesc { #[derive(Debug)] pub enum SortError { + BadGeoPointUsage { name: String }, InvalidName { name: String }, ReservedName { name: String }, ReservedNameForSettings { name: String }, @@ -151,6 +152,9 @@ impl From for SortError { fn from(error: AscDescError) -> Self { match error { AscDescError::InvalidSyntax { name } => SortError::InvalidName { name }, + AscDescError::ReservedKeyword { name } if name.starts_with("_geoPoint") => { + SortError::BadGeoPointUsage { name } + } AscDescError::ReservedKeyword { name } if &name == "_geo" => { SortError::ReservedNameForSettings { name: "_geoPoint".to_string() } } @@ -165,6 +169,14 @@ impl From for SortError { impl fmt::Display for SortError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { + Self::BadGeoPointUsage { name } => { + write!( + f, + "invalid syntax for the `_geoPoint` parameter: `{}`. \ +Usage: `_geoPoint(latitude, longitude):asc`", + name + ) + } Self::InvalidName { name } => { write!(f, "invalid syntax for the sort parameter {}", name) }