From c70f37566933137ebae4c1c49a4bcaff171119a0 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 4 Oct 2022 11:07:14 +0200 Subject: [PATCH] Implement ErrorCode on the heed Error --- meilisearch-http/src/routes/mod.rs | 1 + meilisearch-types/src/error.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/meilisearch-http/src/routes/mod.rs b/meilisearch-http/src/routes/mod.rs index 312742cb7..7cb893095 100644 --- a/meilisearch-http/src/routes/mod.rs +++ b/meilisearch-http/src/routes/mod.rs @@ -2,6 +2,7 @@ use std::collections::BTreeMap; use actix_web::web::Data; use actix_web::{web, HttpRequest, HttpResponse}; +use index::{Settings, Unchecked}; use index_scheduler::{IndexScheduler, Query, Status}; use log::debug; use serde::{Deserialize, Serialize}; diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index b6383263f..725fc8360 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -2,6 +2,7 @@ use std::fmt; use actix_web::{self as aweb, http::StatusCode, HttpResponseBuilder}; use aweb::rt::task::JoinError; +use milli::heed::{Error as HeedError, MdbError}; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] @@ -392,6 +393,22 @@ impl ErrorCode for milli::Error { } } +impl ErrorCode for HeedError { + fn error_code(&self) -> Code { + match self { + HeedError::Mdb(MdbError::MapFull) => Code::DatabaseSizeLimitReached, + HeedError::Mdb(MdbError::Invalid) => Code::InvalidStore, + HeedError::Io(_) + | HeedError::Mdb(_) + | HeedError::Encoding + | HeedError::Decoding + | HeedError::InvalidDatabaseTyping + | HeedError::DatabaseClosing + | HeedError::BadOpenOptions => Code::Internal, + } + } +} + #[cfg(feature = "test-traits")] mod strategy { use proptest::strategy::Strategy;