2021-06-15 03:26:35 +08:00
|
|
|
use std::error::Error;
|
|
|
|
|
|
|
|
use meilisearch_error::{Code, ErrorCode};
|
|
|
|
use serde_json::Value;
|
|
|
|
|
|
|
|
pub type Result<T> = std::result::Result<T, IndexError>;
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum IndexError {
|
|
|
|
#[error("Internal error: {0}")]
|
|
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
|
|
|
#[error("Document with id {0} not found.")]
|
|
|
|
DocumentNotFound(String),
|
|
|
|
#[error("error with facet: {0}")]
|
|
|
|
Facet(#[from] FacetError),
|
|
|
|
}
|
|
|
|
|
2021-06-15 23:55:27 +08:00
|
|
|
internal_error!(
|
|
|
|
IndexError:
|
|
|
|
std::io::Error,
|
|
|
|
heed::Error,
|
|
|
|
fst::Error,
|
|
|
|
serde_json::Error
|
|
|
|
);
|
2021-06-15 03:26:35 +08:00
|
|
|
|
|
|
|
impl ErrorCode for IndexError {
|
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
|
|
|
IndexError::Internal(_) => Code::Internal,
|
|
|
|
IndexError::DocumentNotFound(_) => Code::DocumentNotFound,
|
|
|
|
IndexError::Facet(e) => e.error_code(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum FacetError {
|
|
|
|
#[error("Invalid facet expression, expected {}, found: {1}", .0.join(", "))]
|
2021-06-15 23:39:07 +08:00
|
|
|
InvalidExpression(&'static [&'static str], Value),
|
2021-06-15 03:26:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 23:39:07 +08:00
|
|
|
impl ErrorCode for FacetError {
|
2021-06-15 03:26:35 +08:00
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
|
|
|
FacetError::InvalidExpression(_, _) => Code::Facet,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|