fix the error handling on the criterion side

This commit is contained in:
Tamo 2021-09-22 15:09:07 +02:00
parent ad3befaaf5
commit 113a061bee
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
2 changed files with 189 additions and 28 deletions

View file

@ -57,14 +57,18 @@ pub enum UserError {
AttributeLimitReached,
DocumentLimitReached,
InvalidAscDescSyntax { name: String },
InvalidReservedAscDescSyntax { name: String },
InvalidDocumentId { document_id: Value },
InvalidFacetsDistribution { invalid_facets_name: HashSet<String> },
InvalidFilter(pest::error::Error<ParserRule>),
InvalidFilterAttribute(pest::error::Error<ParserRule>),
InvalidSortName { name: String },
InvalidReservedSortName { name: String },
InvalidGeoField { document_id: Value, object: Value },
InvalidRankingRuleName { name: String },
InvalidReservedRankingRuleName { name: String },
InvalidReservedRankingRuleNameSort { name: String },
InvalidReservedRankingRuleNameFilter { name: String },
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
SortRankingRuleMissing,
InvalidStoreFile,
@ -230,10 +234,40 @@ impl fmt::Display for UserError {
"the document with the id: {} contains an invalid _geo field: {}",
document_id, object
),
Self::InvalidRankingRuleName { name } => write!(f, "invalid criterion {}", 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 } => {
write!(f, "{} is a reserved keyword and thus can't be used as a ranking rule", name)
}
Self::InvalidReservedRankingRuleNameSort { name } => {
write!(
f,
"{0} is a reserved keyword and thus can't be used as a ranking rule. \
{0} can only be used for sorting at search time",
name
)
}
Self::InvalidReservedRankingRuleNameFilter { name } => {
write!(
f,
"{0} is a reserved keyword and thus can't be used as a ranking rule. \
{0} can only be used for filtering at search time",
name
)
}
Self::InvalidReservedSortName { name } => {
write!(
f,
"{} is a reserved keyword and thus can't be used as a sort expression",
name
)
}
Self::InvalidDocumentId { document_id } => {
let json = serde_json::to_string(document_id).unwrap();
write!(