mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-12 16:08:55 +01:00
Introduce some way to construct an Error
This commit is contained in:
parent
23fcf7920e
commit
44c353fafd
@ -1,6 +1,9 @@
|
||||
use std::io;
|
||||
|
||||
use crate::{DocumentId, FieldId};
|
||||
use heed::{MdbError, Error as HeedError};
|
||||
|
||||
pub type Object = serde_json::Map<String, serde_json::Value>;
|
||||
|
||||
pub enum Error {
|
||||
InternalError(InternalError),
|
||||
@ -12,6 +15,16 @@ pub enum InternalError {
|
||||
DatabaseMissingEntry(DatabaseMissingEntry),
|
||||
FieldIdMapMissingEntry(FieldIdMapMissingEntry),
|
||||
IndexingMergingKeys(IndexingMergingKeys),
|
||||
SerializationError(SerializationError),
|
||||
StoreError(MdbError),
|
||||
InvalidDatabaseTyping,
|
||||
DatabaseClosing,
|
||||
}
|
||||
|
||||
pub enum SerializationError {
|
||||
Decoding { db_name: Option<&'static str> },
|
||||
Encoding { db_name: Option<&'static str> },
|
||||
InvalidNumberSerialization,
|
||||
}
|
||||
|
||||
pub enum IndexingMergingKeys {
|
||||
@ -38,5 +51,40 @@ pub enum DatabaseMissingEntry {
|
||||
}
|
||||
|
||||
pub enum UserError {
|
||||
|
||||
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::*;
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user