2022-09-22 18:14:51 +08:00
|
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2022-09-07 05:49:19 +08:00
|
|
|
|
use milli::heed;
|
2022-09-06 22:43:59 +08:00
|
|
|
|
use thiserror::Error;
|
|
|
|
|
|
2022-09-21 23:13:09 +08:00
|
|
|
|
use crate::TaskId;
|
|
|
|
|
|
2022-09-06 22:43:59 +08:00
|
|
|
|
#[derive(Error, Debug)]
|
|
|
|
|
pub enum Error {
|
2022-09-08 03:27:06 +08:00
|
|
|
|
#[error("Index `{0}` not found")]
|
2022-09-08 02:08:07 +08:00
|
|
|
|
IndexNotFound(String),
|
2022-09-08 03:27:06 +08:00
|
|
|
|
#[error("Index `{0}` already exists")]
|
2022-09-08 02:08:07 +08:00
|
|
|
|
IndexAlreadyExists(String),
|
2022-09-07 05:49:19 +08:00
|
|
|
|
#[error("Corrupted task queue.")]
|
|
|
|
|
CorruptedTaskQueue,
|
2022-09-21 23:13:09 +08:00
|
|
|
|
#[error("Task `{0}` not found")]
|
|
|
|
|
TaskNotFound(TaskId),
|
2022-09-22 18:14:51 +08:00
|
|
|
|
|
|
|
|
|
// maybe the two next errors are going to move to the frontend
|
|
|
|
|
#[error("`{0}` is not a status. Available status are")]
|
|
|
|
|
InvalidStatus(String),
|
|
|
|
|
#[error("`{0}` is not a type. Available types are")]
|
|
|
|
|
InvalidKind(String),
|
|
|
|
|
|
2022-09-07 05:49:19 +08:00
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Heed(#[from] heed::Error),
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Milli(#[from] milli::Error),
|
2022-09-14 22:16:53 +08:00
|
|
|
|
#[error(transparent)]
|
2022-09-08 02:30:33 +08:00
|
|
|
|
IndexError(#[from] index::error::IndexError),
|
2022-09-08 03:27:06 +08:00
|
|
|
|
#[error(transparent)]
|
2022-09-14 22:16:53 +08:00
|
|
|
|
FileStore(#[from] file_store::Error),
|
|
|
|
|
#[error(transparent)]
|
2022-09-08 03:27:06 +08:00
|
|
|
|
IoError(#[from] std::io::Error),
|
2022-09-07 05:49:19 +08:00
|
|
|
|
|
|
|
|
|
#[error(transparent)]
|
|
|
|
|
Anyhow(#[from] anyhow::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-09-22 18:47:09 +08:00
|
|
|
|
Error::InvalidStatus(_) => Code::BadRequest,
|
|
|
|
|
Error::InvalidKind(_) => Code::BadRequest,
|
|
|
|
|
|
|
|
|
|
// TODO: TAMO: are all these errors really internal?
|
|
|
|
|
Error::Heed(_) => Code::Internal,
|
|
|
|
|
Error::Milli(_) => Code::Internal,
|
|
|
|
|
Error::IndexError(_) => Code::Internal,
|
|
|
|
|
Error::FileStore(_) => Code::Internal,
|
|
|
|
|
Error::IoError(_) => Code::Internal,
|
2022-09-22 18:14:51 +08:00
|
|
|
|
Error::Anyhow(_) => Code::Internal,
|
|
|
|
|
Error::CorruptedTaskQueue => Code::Internal,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|