2021-06-15 03:26:35 +08:00
|
|
|
use std::error::Error;
|
|
|
|
|
2022-06-06 18:38:46 +08:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
|
|
|
use meilisearch_types::internal_error;
|
2021-06-15 03:26:35 +08:00
|
|
|
use serde_json::Value;
|
|
|
|
|
2022-01-19 18:21:19 +08:00
|
|
|
use crate::{error::MilliError, update_file_store};
|
2021-06-17 20:36:32 +08:00
|
|
|
|
2021-06-15 03:26:35 +08:00
|
|
|
pub type Result<T> = std::result::Result<T, IndexError>;
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum IndexError {
|
2021-11-03 21:25:49 +08:00
|
|
|
#[error("An internal error has occurred. `{0}`.")]
|
2021-06-15 03:26:35 +08:00
|
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
2021-10-27 01:36:48 +08:00
|
|
|
#[error("Document `{0}` not found.")]
|
2021-06-15 03:26:35 +08:00
|
|
|
DocumentNotFound(String),
|
2021-06-24 16:53:51 +08:00
|
|
|
#[error("{0}")]
|
2021-06-15 03:26:35 +08:00
|
|
|
Facet(#[from] FacetError),
|
2021-06-17 20:36:32 +08:00
|
|
|
#[error("{0}")]
|
|
|
|
Milli(#[from] milli::Error),
|
2021-06-15 03:26:35 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 23:55:27 +08:00
|
|
|
internal_error!(
|
2021-06-17 20:38:52 +08:00
|
|
|
IndexError: std::io::Error,
|
2022-03-16 20:45:58 +08:00
|
|
|
milli::heed::Error,
|
2021-06-15 23:55:27 +08:00
|
|
|
fst::Error,
|
2022-01-19 18:21:19 +08:00
|
|
|
serde_json::Error,
|
|
|
|
update_file_store::UpdateFileStoreError,
|
|
|
|
milli::documents::Error
|
2021-06-15 23:55:27 +08:00
|
|
|
);
|
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(),
|
2021-06-17 20:36:32 +08:00
|
|
|
IndexError::Milli(e) => MilliError(e).error_code(),
|
2021-06-15 03:26:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-16 21:58:39 +08:00
|
|
|
impl From<milli::UserError> for IndexError {
|
|
|
|
fn from(error: milli::UserError) -> IndexError {
|
|
|
|
IndexError::Milli(error.into())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-15 03:26:35 +08:00
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum FacetError {
|
2021-10-27 01:36:48 +08:00
|
|
|
#[error("Invalid syntax for the filter parameter: `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 {
|
2021-10-27 01:36:48 +08:00
|
|
|
FacetError::InvalidExpression(_, _) => Code::Filter,
|
2021-06-15 03:26:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|