create an asc_desc error type that is never supposed to be returned to the end user

This commit is contained in:
Tamo 2021-09-22 15:33:32 +02:00
parent 257e621d40
commit 86e272856a
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
3 changed files with 6 additions and 25 deletions

View File

@ -4,7 +4,7 @@ use std::str::FromStr;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::error::{Error, UserError}; use crate::error::{Error, UserError};
use crate::{AscDesc, Member}; use crate::{AscDesc, AscDescError, Member};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum Criterion { pub enum Criterion {
@ -58,31 +58,24 @@ impl FromStr for Criterion {
name: "_geoPoint".to_string(), name: "_geoPoint".to_string(),
})? })?
} }
Err(UserError::InvalidAscDescSyntax { name }) => { Err(AscDescError::InvalidSyntax { name }) => {
Err(UserError::InvalidRankingRuleName { name })? Err(UserError::InvalidRankingRuleName { name })?
} }
Err(UserError::InvalidReservedAscDescSyntax { name }) Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoPoint") => {
if name.starts_with("_geoPoint") =>
{
Err(UserError::InvalidReservedRankingRuleNameSort { Err(UserError::InvalidReservedRankingRuleNameSort {
name: "_geoPoint".to_string(), name: "_geoPoint".to_string(),
} }
.into()) .into())
} }
Err(UserError::InvalidReservedAscDescSyntax { name }) Err(AscDescError::ReservedKeyword { name }) if name.starts_with("_geoRadius") => {
if name.starts_with("_geoRadius") =>
{
Err(UserError::InvalidReservedRankingRuleNameFilter { Err(UserError::InvalidReservedRankingRuleNameFilter {
name: "_geoRadius".to_string(), name: "_geoRadius".to_string(),
} }
.into()) .into())
} }
Err(UserError::InvalidReservedAscDescSyntax { name }) => { Err(AscDescError::ReservedKeyword { name }) => {
Err(UserError::InvalidReservedRankingRuleName { name }.into()) Err(UserError::InvalidReservedRankingRuleName { name }.into())
} }
Err(error) => {
Err(UserError::InvalidRankingRuleName { name: error.to_string() }.into())
}
}, },
} }
} }

View File

@ -56,8 +56,6 @@ pub enum FieldIdMapMissingEntry {
pub enum UserError { pub enum UserError {
AttributeLimitReached, AttributeLimitReached,
DocumentLimitReached, DocumentLimitReached,
InvalidAscDescSyntax { name: String },
InvalidReservedAscDescSyntax { name: String },
InvalidDocumentId { document_id: Value }, InvalidDocumentId { document_id: Value },
InvalidFacetsDistribution { invalid_facets_name: HashSet<String> }, InvalidFacetsDistribution { invalid_facets_name: HashSet<String> },
InvalidFilter(pest::error::Error<ParserRule>), InvalidFilter(pest::error::Error<ParserRule>),
@ -226,22 +224,12 @@ impl fmt::Display for UserError {
) )
} }
Self::InvalidFilter(error) => error.fmt(f), Self::InvalidFilter(error) => error.fmt(f),
Self::InvalidAscDescSyntax { name } => {
write!(f, "invalid asc/desc syntax for {}", name)
}
Self::InvalidGeoField { document_id, object } => write!( Self::InvalidGeoField { document_id, object } => write!(
f, f,
"the document with the id: {} contains an invalid _geo field: {}", "the document with the id: {} contains an invalid _geo field: {}",
document_id, object document_id, object
), ),
Self::InvalidRankingRuleName { name } => write!(f, "invalid ranking rule {}", name), 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 } => { Self::InvalidReservedRankingRuleName { name } => {
write!(f, "{} is a reserved keyword and thus can't be used as a ranking rule", name) write!(f, "{} is a reserved keyword and thus can't be used as a ranking rule", name)
} }

View File

@ -25,7 +25,7 @@ use fxhash::{FxHasher32, FxHasher64};
pub use grenad::CompressionType; pub use grenad::CompressionType;
use serde_json::{Map, Value}; 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::criterion::{default_criteria, Criterion};
pub use self::error::{ pub use self::error::{
Error, FieldIdMapMissingEntry, InternalError, SerializationError, UserError, Error, FieldIdMapMissingEntry, InternalError, SerializationError, UserError,