MeiliSearch/meilisearch-lib/src/dump/error.rs

43 lines
1.1 KiB
Rust
Raw Normal View History

use meilisearch_auth::error::AuthControllerError;
use meilisearch_types::error::{Code, ErrorCode};
use meilisearch_types::internal_error;
use crate::{index_resolver::error::IndexResolverError, tasks::error::TaskError};
2022-05-19 14:44:24 +02:00
pub type Result<T> = std::result::Result<T, DumpError>;
#[derive(thiserror::Error, Debug)]
2022-05-19 14:44:24 +02:00
pub enum DumpError {
2021-11-03 14:25:49 +01:00
#[error("An internal error has occurred. `{0}`.")]
Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
2021-06-24 10:53:51 +02:00
#[error("{0}")]
2022-07-28 15:33:54 +02:00
IndexResolver(Box<IndexResolverError>),
}
internal_error!(
2022-05-19 14:44:24 +02:00
DumpError: milli::heed::Error,
std::io::Error,
tokio::task::JoinError,
tokio::sync::oneshot::error::RecvError,
serde_json::error::Error,
tempfile::PersistError,
fs_extra::error::Error,
AuthControllerError,
TaskError
);
2022-07-28 15:33:54 +02:00
impl From<IndexResolverError> for DumpError {
fn from(e: IndexResolverError) -> Self {
Self::IndexResolver(Box::new(e))
}
}
2022-05-19 14:44:24 +02:00
impl ErrorCode for DumpError {
fn error_code(&self) -> Code {
match self {
2022-05-19 14:44:24 +02:00
DumpError::Internal(_) => Code::Internal,
DumpError::IndexResolver(e) => e.error_code(),
}
}
}