2021-06-14 21:26:35 +02:00
|
|
|
use std::error::Error;
|
2021-09-28 22:22:59 +02:00
|
|
|
use std::fmt;
|
2021-06-14 21:26:35 +02:00
|
|
|
|
2022-06-06 12:38:46 +02:00
|
|
|
use meilisearch_types::{internal_error, Code, ErrorCode};
|
2021-06-14 21:26:35 +02:00
|
|
|
|
2021-10-06 13:01:02 +02:00
|
|
|
use crate::{
|
|
|
|
document_formats::DocumentFormatError,
|
|
|
|
index::error::IndexError,
|
|
|
|
index_controller::{update_file_store::UpdateFileStoreError, DocumentAdditionFormat},
|
|
|
|
};
|
2021-09-28 19:29:14 +02:00
|
|
|
|
2021-09-24 11:53:11 +02:00
|
|
|
pub type Result<T> = std::result::Result<T, UpdateLoopError>;
|
2021-06-14 21:26:35 +02:00
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
2021-06-17 14:38:52 +02:00
|
|
|
#[allow(clippy::large_enum_variant)]
|
2021-09-24 11:53:11 +02:00
|
|
|
pub enum UpdateLoopError {
|
2021-10-26 19:36:48 +02:00
|
|
|
#[error("Task `{0}` not found.")]
|
2021-06-14 21:26:35 +02:00
|
|
|
UnexistingUpdate(u64),
|
2021-11-03 14:25:49 +01:00
|
|
|
#[error("An internal error has occurred. `{0}`.")]
|
2021-06-14 21:26:35 +02:00
|
|
|
Internal(Box<dyn Error + Send + Sync + 'static>),
|
|
|
|
#[error(
|
2021-06-21 13:57:32 +02:00
|
|
|
"update store was shut down due to a fatal error, please check your logs for more info."
|
2021-06-14 21:26:35 +02:00
|
|
|
)]
|
|
|
|
FatalUpdateStoreError,
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("{0}")]
|
2021-09-30 10:35:24 +02:00
|
|
|
DocumentFormatError(#[from] DocumentFormatError),
|
2021-10-26 19:36:48 +02:00
|
|
|
#[error("The provided payload reached the size limit.")]
|
|
|
|
PayloadTooLarge,
|
2021-09-30 11:29:27 +02:00
|
|
|
#[error("A {0} payload is missing.")]
|
|
|
|
MissingPayload(DocumentAdditionFormat),
|
2021-10-04 18:31:05 +02:00
|
|
|
#[error("{0}")]
|
|
|
|
IndexError(#[from] IndexError),
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 11:53:11 +02:00
|
|
|
impl<T> From<tokio::sync::mpsc::error::SendError<T>> for UpdateLoopError
|
2021-09-28 22:22:59 +02:00
|
|
|
where
|
|
|
|
T: Sync + Send + 'static + fmt::Debug,
|
2021-09-22 15:07:04 +02:00
|
|
|
{
|
|
|
|
fn from(other: tokio::sync::mpsc::error::SendError<T>) -> Self {
|
|
|
|
Self::Internal(Box::new(other))
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 11:53:11 +02:00
|
|
|
impl From<tokio::sync::oneshot::error::RecvError> for UpdateLoopError {
|
2021-09-22 15:07:04 +02:00
|
|
|
fn from(other: tokio::sync::oneshot::error::RecvError) -> Self {
|
|
|
|
Self::Internal(Box::new(other))
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 19:36:48 +02:00
|
|
|
impl From<actix_web::error::PayloadError> for UpdateLoopError {
|
|
|
|
fn from(other: actix_web::error::PayloadError) -> Self {
|
|
|
|
match other {
|
|
|
|
actix_web::error::PayloadError::Overflow => Self::PayloadTooLarge,
|
|
|
|
_ => Self::Internal(Box::new(other)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-14 21:26:35 +02:00
|
|
|
internal_error!(
|
2021-09-24 11:53:11 +02:00
|
|
|
UpdateLoopError: heed::Error,
|
2021-06-14 21:26:35 +02:00
|
|
|
std::io::Error,
|
|
|
|
serde_json::Error,
|
2021-09-28 19:29:14 +02:00
|
|
|
tokio::task::JoinError,
|
|
|
|
UpdateFileStoreError
|
2021-06-14 21:26:35 +02:00
|
|
|
);
|
|
|
|
|
2021-09-24 11:53:11 +02:00
|
|
|
impl ErrorCode for UpdateLoopError {
|
2021-06-14 21:26:35 +02:00
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
2021-10-26 19:36:48 +02:00
|
|
|
Self::UnexistingUpdate(_) => Code::TaskNotFound,
|
2021-09-22 15:46:25 +02:00
|
|
|
Self::Internal(_) => Code::Internal,
|
|
|
|
Self::FatalUpdateStoreError => Code::Internal,
|
2021-09-30 10:35:24 +02:00
|
|
|
Self::DocumentFormatError(error) => error.error_code(),
|
2021-10-26 19:36:48 +02:00
|
|
|
Self::PayloadTooLarge => Code::PayloadTooLarge,
|
2021-09-30 11:29:27 +02:00
|
|
|
Self::MissingPayload(_) => Code::MissingPayload,
|
2021-10-04 18:31:05 +02:00
|
|
|
Self::IndexError(e) => e.error_code(),
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|