mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use std::error::Error;
|
|
|
|
use meilisearch_error::{Code, ErrorCode};
|
|
use serde_json::Value;
|
|
|
|
use crate::error::MilliError;
|
|
|
|
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),
|
|
#[error("{0}")]
|
|
Milli(#[from] milli::Error),
|
|
}
|
|
|
|
internal_error!(
|
|
IndexError: std::io::Error,
|
|
heed::Error,
|
|
fst::Error,
|
|
serde_json::Error
|
|
);
|
|
|
|
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(),
|
|
IndexError::Milli(e) => MilliError(e).error_code(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
pub enum FacetError {
|
|
#[error("invalid facet expression, expected {}, found: {1}", .0.join(", "))]
|
|
InvalidExpression(&'static [&'static str], Value),
|
|
}
|
|
|
|
impl ErrorCode for FacetError {
|
|
fn error_code(&self) -> Code {
|
|
match self {
|
|
FacetError::InvalidExpression(_, _) => Code::Facet,
|
|
}
|
|
}
|
|
}
|