56 lines
1.5 KiB
Rust
Raw Normal View History

use std::error::Error;
use meilisearch_error::{Code, ErrorCode};
use serde_json::Value;
2021-06-17 14:36:32 +02:00
use crate::error::MilliError;
pub type Result<T> = std::result::Result<T, IndexError>;
#[derive(Debug, thiserror::Error)]
pub enum IndexError {
2021-06-24 10:53:51 +02:00
#[error("Internal error: {0}")]
Internal(Box<dyn Error + Send + Sync + 'static>),
2021-06-24 10:53:51 +02:00
#[error("Document with id {0} not found.")]
DocumentNotFound(String),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
Facet(#[from] FacetError),
2021-06-17 14:36:32 +02:00
#[error("{0}")]
Milli(#[from] milli::Error),
2021-09-24 11:53:11 +02:00
#[error("A primary key is already present. It's impossible to update it")]
ExistingPrimaryKey,
}
2021-06-15 17:55:27 +02:00
internal_error!(
2021-06-17 14:38:52 +02:00
IndexError: std::io::Error,
2021-06-15 17:55:27 +02:00
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(),
2021-06-17 14:36:32 +02:00
IndexError::Milli(e) => MilliError(e).error_code(),
2021-09-24 11:53:11 +02:00
IndexError::ExistingPrimaryKey => Code::PrimaryKeyAlreadyPresent,
}
}
}
#[derive(Debug, thiserror::Error)]
pub enum FacetError {
2021-06-24 10:53:51 +02:00
#[error("Invalid facet expression, expected {}, found: {1}", .0.join(", "))]
2021-06-15 17:39:07 +02:00
InvalidExpression(&'static [&'static str], Value),
}
2021-06-15 17:39:07 +02:00
impl ErrorCode for FacetError {
fn error_code(&self) -> Code {
match self {
FacetError::InvalidExpression(_, _) => Code::Facet,
}
}
}