From 44c353fafd97217e74a182b3bbb802e33d16f1a6 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 10 Jun 2021 15:55:22 +0200 Subject: [PATCH] Introduce some way to construct an Error --- milli/src/error.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/milli/src/error.rs b/milli/src/error.rs index 02740377c..c6dc85e9c 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -1,6 +1,9 @@ use std::io; use crate::{DocumentId, FieldId}; +use heed::{MdbError, Error as HeedError}; + +pub type Object = serde_json::Map; 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 for Error { + fn from(error: io::Error) -> Error { + // TODO must be improved and more precise + Error::IoError(error) + } +} + +impl From 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), + } + } }