meilisearch/meilisearch-lib/src/index_controller/dump_actor/error.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

use meilisearch_error::{Code, ErrorCode};
2021-09-24 17:53:11 +08:00
use crate::index_controller::index_resolver::error::IndexResolverError;
use crate::index_controller::updates::error::UpdateLoopError;
pub type Result<T> = std::result::Result<T, DumpActorError>;
#[derive(thiserror::Error, Debug)]
pub enum DumpActorError {
2021-06-24 16:53:51 +08:00
#[error("Another dump is already in progress")]
DumpAlreadyRunning,
2021-06-24 16:53:51 +08:00
#[error("Dump `{0}` not found")]
DumpDoesNotExist(String),
2021-06-24 16:53:51 +08:00
#[error("Internal error: {0}")]
Internal(Box<dyn std::error::Error + Send + Sync + 'static>),
2021-06-24 16:53:51 +08:00
#[error("{0}")]
2021-09-24 17:53:11 +08:00
IndexResolver(#[from] IndexResolverError),
2021-06-24 16:53:51 +08:00
#[error("{0}")]
2021-09-24 17:53:11 +08:00
UpdateLoop(#[from] UpdateLoopError),
}
macro_rules! internal_error {
($($other:path), *) => {
$(
impl From<$other> for DumpActorError {
fn from(other: $other) -> Self {
Self::Internal(Box::new(other))
}
}
)*
}
}
internal_error!(
heed::Error,
std::io::Error,
tokio::task::JoinError,
serde_json::error::Error,
tempfile::PersistError
);
impl ErrorCode for DumpActorError {
fn error_code(&self) -> Code {
match self {
DumpActorError::DumpAlreadyRunning => Code::DumpAlreadyInProgress,
2021-06-23 21:06:36 +08:00
DumpActorError::DumpDoesNotExist(_) => Code::NotFound,
DumpActorError::Internal(_) => Code::Internal,
2021-09-24 17:53:11 +08:00
DumpActorError::IndexResolver(e) => e.error_code(),
DumpActorError::UpdateLoop(e) => e.error_code(),
}
}
}