From 86e272856ad03071c1d67aea8d8aefa2dc532f27 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 22 Sep 2021 15:33:32 +0200 Subject: [PATCH] create an asc_desc error type that is never supposed to be returned to the end user --- milli/src/criterion.rs | 17 +++++------------ milli/src/error.rs | 12 ------------ milli/src/lib.rs | 2 +- 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/milli/src/criterion.rs b/milli/src/criterion.rs index acc0148bb..3afc1b1f8 100644 --- a/milli/src/criterion.rs +++ b/milli/src/criterion.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; use crate::error::{Error, UserError}; -use crate::{AscDesc, Member}; +use crate::{AscDesc, AscDescError, Member}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] pub enum Criterion { @@ -58,31 +58,24 @@ impl FromStr for Criterion { name: "_geoPoint".to_string(), })? } - Err(UserError::InvalidAscDescSyntax { name }) => { + Err(AscDescError::InvalidSyntax { name }) => { Err(UserError::InvalidRankingRuleName { name })? } - Err(UserError::InvalidReservedAscDescSyntax { name }) - if name.starts_with("_geoPoint") => - { + Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoPoint") => { Err(UserError::InvalidReservedRankingRuleNameSort { name: "_geoPoint".to_string(), } .into()) } - Err(UserError::InvalidReservedAscDescSyntax { name }) - if name.starts_with("_geoRadius") => - { + Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoRadius") => { Err(UserError::InvalidReservedRankingRuleNameFilter { name: "_geoRadius".to_string(), } .into()) } - Err(UserError::InvalidReservedAscDescSyntax { name }) => { + Err(AscDescError::ReservedKeyword { name }) => { Err(UserError::InvalidReservedRankingRuleName { name }.into()) } - Err(error) => { - Err(UserError::InvalidRankingRuleName { name: error.to_string() }.into()) - } }, } } diff --git a/milli/src/error.rs b/milli/src/error.rs index 2e2d3088e..1c0125c70 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -56,8 +56,6 @@ pub enum FieldIdMapMissingEntry { pub enum UserError { AttributeLimitReached, DocumentLimitReached, - InvalidAscDescSyntax { name: String }, - InvalidReservedAscDescSyntax { name: String }, InvalidDocumentId { document_id: Value }, InvalidFacetsDistribution { invalid_facets_name: HashSet }, InvalidFilter(pest::error::Error), @@ -226,22 +224,12 @@ impl fmt::Display for UserError { ) } Self::InvalidFilter(error) => error.fmt(f), - Self::InvalidAscDescSyntax { name } => { - write!(f, "invalid asc/desc syntax for {}", name) - } Self::InvalidGeoField { document_id, object } => write!( f, "the document with the id: {} contains an invalid _geo field: {}", document_id, object ), Self::InvalidRankingRuleName { name } => write!(f, "invalid ranking rule {}", name), - Self::InvalidReservedAscDescSyntax { name } => { - write!( - f, - "{} is a reserved keyword and thus can't be used as a asc/desc rule", - name - ) - } Self::InvalidReservedRankingRuleName { name } => { write!(f, "{} is a reserved keyword and thus can't be used as a ranking rule", name) } diff --git a/milli/src/lib.rs b/milli/src/lib.rs index f36de8437..d61e7d6e3 100644 --- a/milli/src/lib.rs +++ b/milli/src/lib.rs @@ -25,7 +25,7 @@ use fxhash::{FxHasher32, FxHasher64}; pub use grenad::CompressionType; use serde_json::{Map, Value}; -pub use self::asc_desc::{AscDesc, Member}; +pub use self::asc_desc::{AscDesc, AscDescError, Member}; pub use self::criterion::{default_criteria, Criterion}; pub use self::error::{ Error, FieldIdMapMissingEntry, InternalError, SerializationError, UserError,