2019-10-18 19:05:28 +08:00
|
|
|
use crate::serde::{DeserializerError, SerializerError};
|
2019-10-11 22:16:21 +08:00
|
|
|
use serde_json::Error as SerdeJsonError;
|
2020-04-07 02:05:02 +08:00
|
|
|
use pest::error::Error as PestError;
|
|
|
|
use crate::filters::Rule;
|
2019-10-18 19:05:28 +08:00
|
|
|
use std::{error, fmt, io};
|
2019-10-03 21:04:11 +08:00
|
|
|
|
2020-02-03 05:59:19 +08:00
|
|
|
pub use bincode::Error as BincodeError;
|
2020-04-07 02:05:02 +08:00
|
|
|
pub use fst::Error as FstError;
|
|
|
|
pub use heed::Error as HeedError;
|
|
|
|
pub use pest::error as pest_error;
|
2020-02-03 05:59:19 +08:00
|
|
|
|
2019-10-03 23:33:15 +08:00
|
|
|
pub type MResult<T> = Result<T, Error>;
|
|
|
|
|
2019-10-03 21:04:11 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Io(io::Error),
|
2019-10-10 19:38:58 +08:00
|
|
|
IndexAlreadyExists,
|
2020-03-10 01:40:49 +08:00
|
|
|
MissingPrimaryKey,
|
2019-10-03 21:04:11 +08:00
|
|
|
SchemaMissing,
|
|
|
|
WordIndexMissing,
|
|
|
|
MissingDocumentId,
|
2020-01-11 01:20:30 +08:00
|
|
|
MaxFieldsLimitExceeded,
|
2020-01-14 02:10:58 +08:00
|
|
|
Schema(meilisearch_schema::Error),
|
2019-10-21 18:05:53 +08:00
|
|
|
Zlmdb(heed::Error),
|
2019-10-07 22:16:04 +08:00
|
|
|
Fst(fst::Error),
|
2019-10-11 22:16:21 +08:00
|
|
|
SerdeJson(SerdeJsonError),
|
2019-10-07 22:16:04 +08:00
|
|
|
Bincode(bincode::Error),
|
|
|
|
Serializer(SerializerError),
|
2019-10-08 20:53:35 +08:00
|
|
|
Deserializer(DeserializerError),
|
2019-10-07 23:48:26 +08:00
|
|
|
UnsupportedOperation(UnsupportedOperation),
|
2020-04-07 02:05:02 +08:00
|
|
|
FilterParseError(PestError<Rule>)
|
2019-10-07 22:16:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(error: io::Error) -> Error {
|
|
|
|
Error::Io(error)
|
|
|
|
}
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
|
2020-04-07 01:31:24 +08:00
|
|
|
impl From<PestError<Rule>> for Error {
|
|
|
|
fn from(error: PestError<Rule>) -> Error {
|
|
|
|
Error::FilterParseError(error.renamed_rules(|r| {
|
|
|
|
let s = match r {
|
|
|
|
Rule::or => "OR",
|
|
|
|
Rule::and => "AND",
|
|
|
|
Rule::not => "NOT",
|
|
|
|
Rule::string => "string",
|
|
|
|
Rule::word => "word",
|
2020-04-07 02:05:02 +08:00
|
|
|
Rule::greater => "field > value",
|
|
|
|
Rule::less => "field < value",
|
|
|
|
Rule::eq => "field = value",
|
|
|
|
Rule::leq => "field <= value",
|
|
|
|
Rule::geq => "field >= value",
|
2020-04-07 01:31:24 +08:00
|
|
|
Rule::key => "key",
|
|
|
|
_ => "other",
|
|
|
|
};
|
|
|
|
s.to_string()
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-14 02:10:58 +08:00
|
|
|
impl From<meilisearch_schema::Error> for Error {
|
|
|
|
fn from(error: meilisearch_schema::Error) -> Error {
|
|
|
|
Error::Schema(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 05:59:19 +08:00
|
|
|
impl From<HeedError> for Error {
|
|
|
|
fn from(error: HeedError) -> Error {
|
2019-10-16 23:05:24 +08:00
|
|
|
Error::Zlmdb(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 05:59:19 +08:00
|
|
|
impl From<FstError> for Error {
|
|
|
|
fn from(error: FstError) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Fst(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 22:16:21 +08:00
|
|
|
impl From<SerdeJsonError> for Error {
|
|
|
|
fn from(error: SerdeJsonError) -> Error {
|
|
|
|
Error::SerdeJson(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 05:59:19 +08:00
|
|
|
impl From<BincodeError> for Error {
|
|
|
|
fn from(error: BincodeError) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Bincode(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SerializerError> for Error {
|
|
|
|
fn from(error: SerializerError) -> Error {
|
2019-10-07 22:16:04 +08:00
|
|
|
Error::Serializer(error)
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 20:53:35 +08:00
|
|
|
impl From<DeserializerError> for Error {
|
|
|
|
fn from(error: DeserializerError) -> Error {
|
|
|
|
Error::Deserializer(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 23:48:26 +08:00
|
|
|
impl From<UnsupportedOperation> for Error {
|
|
|
|
fn from(op: UnsupportedOperation) -> Error {
|
|
|
|
Error::UnsupportedOperation(op)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 21:04:11 +08:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::Error::*;
|
|
|
|
match self {
|
2019-10-07 22:16:04 +08:00
|
|
|
Io(e) => write!(f, "{}", e),
|
2019-10-10 19:38:58 +08:00
|
|
|
IndexAlreadyExists => write!(f, "index already exists"),
|
2020-03-10 22:35:19 +08:00
|
|
|
MissingPrimaryKey => write!(f, "schema cannot be built without a primary key"),
|
2019-10-03 21:04:11 +08:00
|
|
|
SchemaMissing => write!(f, "this index does not have a schema"),
|
|
|
|
WordIndexMissing => write!(f, "this index does not have a word index"),
|
|
|
|
MissingDocumentId => write!(f, "document id is missing"),
|
2020-02-11 22:16:02 +08:00
|
|
|
MaxFieldsLimitExceeded => write!(f, "maximum number of fields in a document exceeded"),
|
|
|
|
Schema(e) => write!(f, "schema error; {}", e),
|
2019-10-21 18:05:53 +08:00
|
|
|
Zlmdb(e) => write!(f, "heed error; {}", e),
|
2019-10-07 22:16:04 +08:00
|
|
|
Fst(e) => write!(f, "fst error; {}", e),
|
2019-10-11 22:16:21 +08:00
|
|
|
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
2019-10-07 22:16:04 +08:00
|
|
|
Bincode(e) => write!(f, "bincode error; {}", e),
|
|
|
|
Serializer(e) => write!(f, "serializer error; {}", e),
|
2019-10-08 20:53:35 +08:00
|
|
|
Deserializer(e) => write!(f, "deserializer error; {}", e),
|
2019-10-07 23:48:26 +08:00
|
|
|
UnsupportedOperation(op) => write!(f, "unsupported operation; {}", op),
|
2020-04-07 02:05:02 +08:00
|
|
|
FilterParseError(e) => write!(f, "error parsing filter; {}", e),
|
2019-10-03 21:04:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 19:05:28 +08:00
|
|
|
impl error::Error for Error {}
|
2019-10-03 21:04:11 +08:00
|
|
|
|
2019-10-07 23:48:26 +08:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum UnsupportedOperation {
|
|
|
|
SchemaAlreadyExists,
|
2020-03-10 01:40:49 +08:00
|
|
|
CannotUpdateSchemaPrimaryKey,
|
2019-10-21 23:33:52 +08:00
|
|
|
CannotReorderSchemaAttribute,
|
2019-11-05 19:02:42 +08:00
|
|
|
CanOnlyIntroduceNewSchemaAttributesAtEnd,
|
2019-10-21 23:33:52 +08:00
|
|
|
CannotRemoveSchemaAttribute,
|
2019-10-07 23:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for UnsupportedOperation {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::UnsupportedOperation::*;
|
|
|
|
match self {
|
|
|
|
SchemaAlreadyExists => write!(f, "Cannot update index which already have a schema"),
|
2020-03-10 01:40:49 +08:00
|
|
|
CannotUpdateSchemaPrimaryKey => write!(f, "Cannot update the primary key of a schema"),
|
2019-10-21 23:33:52 +08:00
|
|
|
CannotReorderSchemaAttribute => write!(f, "Cannot reorder the attributes of a schema"),
|
2019-11-05 19:02:42 +08:00
|
|
|
CanOnlyIntroduceNewSchemaAttributesAtEnd => {
|
|
|
|
write!(f, "Can only introduce new attributes at end of a schema")
|
2019-10-21 23:33:52 +08:00
|
|
|
}
|
|
|
|
CannotRemoveSchemaAttribute => write!(f, "Cannot remove attributes from a schema"),
|
2019-10-07 23:48:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|