2022-10-13 21:02:59 +08:00
|
|
|
use meilisearch_types::error::{Code, ErrorCode};
|
2022-10-02 19:24:59 +08:00
|
|
|
use thiserror::Error;
|
|
|
|
|
|
|
|
#[derive(Debug, Error)]
|
|
|
|
pub enum Error {
|
2022-10-10 20:32:11 +08:00
|
|
|
#[error("Bad index name.")]
|
2022-10-03 22:12:01 +08:00
|
|
|
BadIndexName,
|
2022-10-10 20:32:11 +08:00
|
|
|
#[error("Malformed task.")]
|
|
|
|
MalformedTask,
|
2022-10-03 22:12:01 +08:00
|
|
|
|
2022-10-02 19:24:59 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
Io(#[from] std::io::Error),
|
|
|
|
#[error(transparent)]
|
|
|
|
Serde(#[from] serde_json::Error),
|
2022-10-04 00:50:06 +08:00
|
|
|
#[error(transparent)]
|
|
|
|
Uuid(#[from] uuid::Error),
|
2022-10-02 19:24:59 +08:00
|
|
|
}
|
2022-10-13 21:02:59 +08:00
|
|
|
|
|
|
|
impl ErrorCode for Error {
|
|
|
|
fn error_code(&self) -> Code {
|
|
|
|
match self {
|
2022-12-20 23:32:51 +08:00
|
|
|
Error::Io(e) => e.error_code(),
|
|
|
|
|
2022-12-21 01:08:44 +08:00
|
|
|
// These errors either happen when creating a dump and don't need any error code,
|
2022-12-21 00:49:38 +08:00
|
|
|
// These error come from a internal bad deserialization.
|
2022-10-13 21:02:59 +08:00
|
|
|
Error::Serde(_) => Code::Internal,
|
|
|
|
Error::Uuid(_) => Code::Internal,
|
|
|
|
|
|
|
|
// all these errors should never be raised when creating a dump, thus no error code should be associated.
|
|
|
|
Error::BadIndexName => Code::Internal,
|
|
|
|
Error::MalformedTask => Code::Internal,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|