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
|
|
|
|
|
|
|
use meilisearch_error::{Code, ErrorCode};
|
|
|
|
|
2021-09-28 22:22:59 +02:00
|
|
|
use crate::{
|
|
|
|
document_formats::DocumentFormatError,
|
2021-09-30 11:29:27 +02:00
|
|
|
index_controller::{update_file_store::UpdateFileStoreError, DocumentAdditionFormat},
|
2021-09-28 22:22:59 +02:00
|
|
|
};
|
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-06-24 10:53:51 +02:00
|
|
|
#[error("Update {0} not found.")]
|
2021-06-14 21:26:35 +02:00
|
|
|
UnexistingUpdate(u64),
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("Internal error: {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-09-28 20:13:26 +02:00
|
|
|
// TODO: The reference to actix has to go.
|
2021-06-24 10:53:51 +02:00
|
|
|
#[error("{0}")]
|
2021-06-23 14:21:20 +02:00
|
|
|
PayloadError(#[from] actix_web::error::PayloadError),
|
2021-09-30 11:29:27 +02:00
|
|
|
#[error("A {0} payload is missing.")]
|
|
|
|
MissingPayload(DocumentAdditionFormat),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-22 15:46:25 +02:00
|
|
|
Self::UnexistingUpdate(_) => Code::NotFound,
|
|
|
|
Self::Internal(_) => Code::Internal,
|
|
|
|
//Self::IndexActor(e) => e.error_code(),
|
|
|
|
Self::FatalUpdateStoreError => Code::Internal,
|
2021-09-30 10:35:24 +02:00
|
|
|
Self::DocumentFormatError(error) => error.error_code(),
|
2021-09-22 15:46:25 +02:00
|
|
|
Self::PayloadError(error) => match error {
|
2021-09-08 12:34:56 +02:00
|
|
|
actix_web::error::PayloadError::Overflow => Code::PayloadTooLarge,
|
2021-06-23 14:48:33 +02:00
|
|
|
_ => Code::Internal,
|
2021-06-23 14:21:20 +02:00
|
|
|
},
|
2021-09-30 11:29:27 +02:00
|
|
|
Self::MissingPayload(_) => Code::MissingPayload,
|
2021-06-14 21:26:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|