2021-06-09 17:05:46 +02:00
|
|
|
use std::io;
|
|
|
|
|
|
|
|
use crate::{DocumentId, FieldId};
|
2021-06-10 15:55:22 +02:00
|
|
|
use heed::{MdbError, Error as HeedError};
|
|
|
|
|
|
|
|
pub type Object = serde_json::Map<String, serde_json::Value>;
|
2021-06-09 17:05:46 +02:00
|
|
|
|
|
|
|
pub enum Error {
|
|
|
|
InternalError(InternalError),
|
|
|
|
IoError(io::Error),
|
|
|
|
UserError(UserError),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum InternalError {
|
|
|
|
DatabaseMissingEntry(DatabaseMissingEntry),
|
|
|
|
FieldIdMapMissingEntry(FieldIdMapMissingEntry),
|
|
|
|
IndexingMergingKeys(IndexingMergingKeys),
|
2021-06-10 15:55:22 +02:00
|
|
|
SerializationError(SerializationError),
|
|
|
|
StoreError(MdbError),
|
|
|
|
InvalidDatabaseTyping,
|
|
|
|
DatabaseClosing,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum SerializationError {
|
|
|
|
Decoding { db_name: Option<&'static str> },
|
|
|
|
Encoding { db_name: Option<&'static str> },
|
|
|
|
InvalidNumberSerialization,
|
2021-06-09 17:05:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum IndexingMergingKeys {
|
|
|
|
DocIdWordPosition,
|
|
|
|
Document,
|
|
|
|
MainFstDeserialization,
|
|
|
|
WordLevelPositionDocids,
|
|
|
|
WordPrefixLevelPositionDocids,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum FieldIdMapMissingEntry {
|
|
|
|
DisplayedFieldId { field_id: FieldId },
|
|
|
|
DisplayedFieldName { field_name: String },
|
|
|
|
FacetedFieldName { field_name: String },
|
|
|
|
FilterableFieldName { field_name: String },
|
|
|
|
SearchableFieldName { field_name: String },
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum DatabaseMissingEntry {
|
|
|
|
DocumentId { internal_id: DocumentId },
|
|
|
|
FacetValuesDocids,
|
|
|
|
IndexCreationTime,
|
|
|
|
IndexUpdateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum UserError {
|
2021-06-10 15:55:22 +02:00
|
|
|
AttributeLimitReached,
|
|
|
|
DocumentLimitReached,
|
|
|
|
InvalidCriterionName { name: String },
|
|
|
|
InvalidDocumentId { document_id: DocumentId },
|
|
|
|
MissingDocumentId { document: Object },
|
|
|
|
MissingPrimaryKey,
|
|
|
|
DatabaseSizeReached,
|
|
|
|
NoSpaceLeftOnDevice,
|
|
|
|
InvalidStoreFile,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(error: io::Error) -> Error {
|
|
|
|
// TODO must be improved and more precise
|
|
|
|
Error::IoError(error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<HeedError> for Error {
|
|
|
|
fn from(error: HeedError) -> Error {
|
|
|
|
use self::Error::*;
|
|
|
|
use self::InternalError::*;
|
|
|
|
use self::SerializationError::*;
|
|
|
|
use self::UserError::*;
|
2021-06-09 17:05:46 +02:00
|
|
|
|
2021-06-10 15:55:22 +02:00
|
|
|
match error {
|
|
|
|
HeedError::Io(error) => Error::from(error),
|
|
|
|
HeedError::Mdb(MdbError::MapFull) => UserError(DatabaseSizeReached),
|
|
|
|
HeedError::Mdb(MdbError::Invalid) => UserError(InvalidStoreFile),
|
|
|
|
HeedError::Mdb(error) => InternalError(StoreError(error)),
|
|
|
|
HeedError::Encoding => InternalError(SerializationError(Encoding { db_name: None })),
|
|
|
|
HeedError::Decoding => InternalError(SerializationError(Decoding { db_name: None })),
|
|
|
|
HeedError::InvalidDatabaseTyping => InternalError(InvalidDatabaseTyping),
|
|
|
|
HeedError::DatabaseClosing => InternalError(DatabaseClosing),
|
|
|
|
}
|
|
|
|
}
|
2021-06-09 17:05:46 +02:00
|
|
|
}
|