2022-09-22 18:14:51 +08:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2022-10-21 00:00:07 +08:00
|
|
|
use meilisearch_types::{heed, milli};
|
2022-09-06 22:43:59 +08:00
|
|
|
use thiserror::Error;
|
|
|
|
|
2022-09-21 23:13:09 +08:00
|
|
|
use crate::TaskId;
|
|
|
|
|
2022-10-22 22:35:42 +08:00
|
|
|
#[allow(clippy::large_enum_variant)]
|
2022-09-06 22:43:59 +08:00
|
|
|
#[derive(Error, Debug)]
|
|
|
|
pub enum Error {
|
2022-10-21 20:12:25 +08:00
|
|
|
#[error("Index `{0}` not found.")]
|
2022-09-08 02:08:07 +08:00
|
|
|
IndexNotFound(String),
|
2022-10-21 20:12:25 +08:00
|
|
|
#[error("Index `{0}` already exists.")]
|
2022-09-08 02:08:07 +08:00
|
|
|
IndexAlreadyExists(String),
|
2022-10-16 07:39:01 +08:00
|
|
|
#[error("Corrupted dump.")]
|
|
|
|
CorruptedDump,
|
2022-10-21 20:12:25 +08:00
|
|
|
#[error("Task `{0}` not found.")]
|
2022-09-21 23:13:09 +08:00
|
|
|
TaskNotFound(TaskId),
|
2022-10-21 20:12:25 +08:00
|
|
|
#[error("Query parameters to filter the tasks to delete are missing. Available query parameters are: `uid`, `indexUid`, `status`, `type`.")]
|
2022-10-15 17:17:06 +08:00
|
|
|
TaskDeletionWithEmptyQuery,
|
2022-10-21 20:12:25 +08:00
|
|
|
#[error("Query parameters to filter the tasks to cancel are missing. Available query parameters are: `uid`, `indexUid`, `status`, `type`.")]
|
2022-10-18 20:48:40 +08:00
|
|
|
TaskCancelationWithEmptyQuery,
|
2022-09-22 18:14:51 +08:00
|
|
|
|
2022-10-13 21:02:59 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
Dump(#[from] dump::Error),
|
2022-09-07 05:49:19 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
Heed(#[from] heed::Error),
|
|
|
|
#[error(transparent)]
|
|
|
|
Milli(#[from] milli::Error),
|
2022-10-25 15:48:51 +08:00
|
|
|
#[error("An unexpected crash occurred when processing the task.")]
|
2022-10-24 20:16:14 +08:00
|
|
|
ProcessBatchPanicked,
|
2022-09-14 22:16:53 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
FileStore(#[from] file_store::Error),
|
|
|
|
#[error(transparent)]
|
2022-09-08 03:27:06 +08:00
|
|
|
IoError(#[from] std::io::Error),
|
2022-10-25 21:51:15 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
Persist(#[from] tempfile::PersistError),
|
2022-09-07 05:49:19 +08:00
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
Anyhow(#[from] anyhow::Error),
|
2022-10-24 20:16:14 +08:00
|
|
|
|
|
|
|
// Irrecoverable errors:
|
|
|
|
#[error(transparent)]
|
|
|
|
CreateBatch(Box<Self>),
|
|
|
|
#[error("Corrupted task queue.")]
|
|
|
|
CorruptedTaskQueue,
|
|
|
|
#[error(transparent)]
|
|
|
|
TaskDatabaseUpdate(Box<Self>),
|
|
|
|
#[error(transparent)]
|
|
|
|
HeedTransaction(heed::Error),
|
2022-09-06 22:43:59 +08:00
|
|
|
}
|
2022-09-22 18:14:51 +08:00
|
|
|
|
|
|
|
impl ErrorCode for Error {
|
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
|
|
|
Error::IndexNotFound(_) => Code::IndexNotFound,
|
|
|
|
Error::IndexAlreadyExists(_) => Code::IndexAlreadyExists,
|
|
|
|
Error::TaskNotFound(_) => Code::TaskNotFound,
|
2022-10-15 17:17:06 +08:00
|
|
|
Error::TaskDeletionWithEmptyQuery => Code::TaskDeletionWithEmptyQuery,
|
2022-10-18 20:48:40 +08:00
|
|
|
Error::TaskCancelationWithEmptyQuery => Code::TaskCancelationWithEmptyQuery,
|
2022-09-22 18:47:09 +08:00
|
|
|
|
2022-10-13 21:02:59 +08:00
|
|
|
Error::Dump(e) => e.error_code(),
|
|
|
|
Error::Milli(e) => e.error_code(),
|
2022-10-24 20:16:14 +08:00
|
|
|
Error::ProcessBatchPanicked => Code::Internal,
|
2022-10-25 21:51:15 +08:00
|
|
|
// TODO: TAMO: are all these errors really internal?
|
2022-09-22 18:47:09 +08:00
|
|
|
Error::Heed(_) => Code::Internal,
|
|
|
|
Error::FileStore(_) => Code::Internal,
|
|
|
|
Error::IoError(_) => Code::Internal,
|
2022-10-25 21:51:15 +08:00
|
|
|
Error::Persist(_) => Code::Internal,
|
2022-09-22 18:14:51 +08:00
|
|
|
Error::Anyhow(_) => Code::Internal,
|
|
|
|
Error::CorruptedTaskQueue => Code::Internal,
|
2022-10-16 07:39:01 +08:00
|
|
|
Error::CorruptedDump => Code::Internal,
|
2022-10-24 20:16:14 +08:00
|
|
|
Error::TaskDatabaseUpdate(_) => Code::Internal,
|
|
|
|
Error::CreateBatch(_) => Code::Internal,
|
|
|
|
Error::HeedTransaction(_) => Code::Internal,
|
2022-09-22 18:14:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|