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

40 lines
1.3 KiB
Rust
Raw Normal View History

use meilisearch_error::{internal_error, Code, ErrorCode};
use crate::{index_resolver::error::IndexResolverError, tasks::error::TaskError};
pub type Result<T> = std::result::Result<T, DumpActorError>;
#[derive(thiserror::Error, Debug)]
pub enum DumpActorError {
2021-11-03 14:25:49 +01:00
#[error("A dump is already processing. You must wait until the current process is finished before requesting another dump.")]
DumpAlreadyRunning,
2021-10-26 19:36:48 +02:00
#[error("Dump `{0}` not found.")]
DumpDoesNotExist(String),
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}")]
2021-09-24 11:53:11 +02:00
IndexResolver(#[from] IndexResolverError),
}
internal_error!(
DumpActorError: heed::Error,
std::io::Error,
tokio::task::JoinError,
tokio::sync::oneshot::error::RecvError,
serde_json::error::Error,
tempfile::PersistError,
fs_extra::error::Error,
TaskError
);
impl ErrorCode for DumpActorError {
fn error_code(&self) -> Code {
match self {
DumpActorError::DumpAlreadyRunning => Code::DumpAlreadyInProgress,
2021-11-03 14:25:49 +01:00
DumpActorError::DumpDoesNotExist(_) => Code::DumpNotFound,
DumpActorError::Internal(_) => Code::Internal,
2021-09-24 11:53:11 +02:00
DumpActorError::IndexResolver(e) => e.error_code(),
}
}
}