mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
improve the error handling in general and introduce the concept of reserved keywords
This commit is contained in:
parent
e8c093c1d0
commit
bd4c248292
6 changed files with 50 additions and 17 deletions
|
@ -12,6 +12,12 @@ use crate::{DocumentId, FieldId};
|
|||
|
||||
pub type Object = Map<String, Value>;
|
||||
|
||||
const RESERVED_KEYWORD: &[&'static str] = &["_geo", "_geoDistance"];
|
||||
|
||||
pub fn is_reserved_keyword(keyword: &str) -> bool {
|
||||
RESERVED_KEYWORD.contains(&keyword)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
InternalError(InternalError),
|
||||
|
@ -60,6 +66,9 @@ pub enum UserError {
|
|||
InvalidFilter(pest::error::Error<ParserRule>),
|
||||
InvalidFilterAttribute(pest::error::Error<ParserRule>),
|
||||
InvalidSortName { name: String },
|
||||
InvalidGeoField { document_id: Value, object: Value },
|
||||
InvalidRankingRuleName { name: String },
|
||||
InvalidReservedRankingRuleName { name: String },
|
||||
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
|
||||
SortRankingRuleMissing,
|
||||
InvalidStoreFile,
|
||||
|
@ -222,6 +231,15 @@ impl fmt::Display for UserError {
|
|||
write!(f, "invalid asc/desc syntax for {}", name)
|
||||
}
|
||||
Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", 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 criterion {}", name),
|
||||
Self::InvalidReservedRankingRuleName { name } => {
|
||||
write!(f, "{} is a reserved keyword and thus can't be used as a ranking rule", name)
|
||||
}
|
||||
Self::InvalidDocumentId { document_id } => {
|
||||
let json = serde_json::to_string(document_id).unwrap();
|
||||
write!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue