2019-10-18 13:05:28 +02:00
|
|
|
use crate::serde::{DeserializerError, SerializerError};
|
2019-10-11 16:16:21 +02:00
|
|
|
use serde_json::Error as SerdeJsonError;
|
2019-10-18 13:05:28 +02:00
|
|
|
use std::{error, fmt, io};
|
2019-10-03 15:04:11 +02:00
|
|
|
|
2019-10-03 17:33:15 +02:00
|
|
|
pub type MResult<T> = Result<T, Error>;
|
|
|
|
|
2019-10-03 15:04:11 +02:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2019-10-07 16:16:04 +02:00
|
|
|
Io(io::Error),
|
2019-10-10 13:38:58 +02:00
|
|
|
IndexAlreadyExists,
|
2019-10-03 15:04:11 +02:00
|
|
|
SchemaDiffer,
|
|
|
|
SchemaMissing,
|
|
|
|
WordIndexMissing,
|
|
|
|
MissingDocumentId,
|
2019-10-21 12:05:53 +02:00
|
|
|
Zlmdb(heed::Error),
|
2019-10-07 16:16:04 +02:00
|
|
|
Fst(fst::Error),
|
2019-10-11 16:16:21 +02:00
|
|
|
SerdeJson(SerdeJsonError),
|
2019-10-07 16:16:04 +02:00
|
|
|
Bincode(bincode::Error),
|
|
|
|
Serializer(SerializerError),
|
2019-10-08 14:53:35 +02:00
|
|
|
Deserializer(DeserializerError),
|
2019-10-07 17:48:26 +02:00
|
|
|
UnsupportedOperation(UnsupportedOperation),
|
2019-10-07 16:16:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(error: io::Error) -> Error {
|
|
|
|
Error::Io(error)
|
|
|
|
}
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
|
2019-10-21 12:05:53 +02:00
|
|
|
impl From<heed::Error> for Error {
|
|
|
|
fn from(error: heed::Error) -> Error {
|
2019-10-16 17:05:24 +02:00
|
|
|
Error::Zlmdb(error)
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<fst::Error> for Error {
|
|
|
|
fn from(error: fst::Error) -> Error {
|
2019-10-07 16:16:04 +02:00
|
|
|
Error::Fst(error)
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-11 16:16:21 +02:00
|
|
|
impl From<SerdeJsonError> for Error {
|
|
|
|
fn from(error: SerdeJsonError) -> Error {
|
|
|
|
Error::SerdeJson(error)
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<bincode::Error> for Error {
|
|
|
|
fn from(error: bincode::Error) -> Error {
|
2019-10-07 16:16:04 +02:00
|
|
|
Error::Bincode(error)
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<SerializerError> for Error {
|
|
|
|
fn from(error: SerializerError) -> Error {
|
2019-10-07 16:16:04 +02:00
|
|
|
Error::Serializer(error)
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-08 14:53:35 +02:00
|
|
|
impl From<DeserializerError> for Error {
|
|
|
|
fn from(error: DeserializerError) -> Error {
|
|
|
|
Error::Deserializer(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 17:48:26 +02:00
|
|
|
impl From<UnsupportedOperation> for Error {
|
|
|
|
fn from(op: UnsupportedOperation) -> Error {
|
|
|
|
Error::UnsupportedOperation(op)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-03 15:04:11 +02:00
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use self::Error::*;
|
|
|
|
match self {
|
2019-10-07 16:16:04 +02:00
|
|
|
Io(e) => write!(f, "{}", e),
|
2019-10-10 13:38:58 +02:00
|
|
|
IndexAlreadyExists => write!(f, "index already exists"),
|
2019-10-03 15:04:11 +02:00
|
|
|
SchemaDiffer => write!(f, "schemas differ"),
|
|
|
|
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"),
|
2019-10-21 12:05:53 +02:00
|
|
|
Zlmdb(e) => write!(f, "heed error; {}", e),
|
2019-10-07 16:16:04 +02:00
|
|
|
Fst(e) => write!(f, "fst error; {}", e),
|
2019-10-11 16:16:21 +02:00
|
|
|
SerdeJson(e) => write!(f, "serde json error; {}", e),
|
2019-10-07 16:16:04 +02:00
|
|
|
Bincode(e) => write!(f, "bincode error; {}", e),
|
|
|
|
Serializer(e) => write!(f, "serializer error; {}", e),
|
2019-10-08 14:53:35 +02:00
|
|
|
Deserializer(e) => write!(f, "deserializer error; {}", e),
|
2019-10-07 17:48:26 +02:00
|
|
|
UnsupportedOperation(op) => write!(f, "unsupported operation; {}", op),
|
2019-10-03 15:04:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
impl error::Error for Error {}
|
2019-10-03 15:04:11 +02:00
|
|
|
|
2019-10-07 17:48:26 +02:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum UnsupportedOperation {
|
|
|
|
SchemaAlreadyExists,
|
2019-10-21 17:33:52 +02:00
|
|
|
CannotUpdateSchemaIdentifier,
|
|
|
|
CannotReorderSchemaAttribute,
|
2019-11-05 12:02:42 +01:00
|
|
|
CanOnlyIntroduceNewSchemaAttributesAtEnd,
|
2019-10-21 17:33:52 +02:00
|
|
|
CannotRemoveSchemaAttribute,
|
2019-10-07 17:48:26 +02: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"),
|
2019-10-21 17:33:52 +02:00
|
|
|
CannotUpdateSchemaIdentifier => write!(f, "Cannot update the identifier of a schema"),
|
|
|
|
CannotReorderSchemaAttribute => write!(f, "Cannot reorder the attributes of a schema"),
|
2019-11-05 12:02:42 +01:00
|
|
|
CanOnlyIntroduceNewSchemaAttributesAtEnd => {
|
|
|
|
write!(f, "Can only introduce new attributes at end of a schema")
|
2019-10-21 17:33:52 +02:00
|
|
|
}
|
|
|
|
CannotRemoveSchemaAttribute => write!(f, "Cannot remove attributes from a schema"),
|
2019-10-07 17:48:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|