From cb48a02f9437fc226ce92ba95c464bb448c0eacf Mon Sep 17 00:00:00 2001 From: Irevoire Date: Sat, 22 Oct 2022 14:19:56 +0200 Subject: [PATCH] fix the invalid index uid errors --- meilisearch-http/src/error.rs | 4 ++++ meilisearch-http/src/routes/indexes/documents.rs | 4 ++++ meilisearch-types/src/index_uid.rs | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/meilisearch-http/src/error.rs b/meilisearch-http/src/error.rs index a40677f97..c6779907c 100644 --- a/meilisearch-http/src/error.rs +++ b/meilisearch-http/src/error.rs @@ -2,6 +2,7 @@ use actix_web as aweb; use aweb::error::{JsonPayloadError, QueryPayloadError}; use meilisearch_types::document_formats::{DocumentFormatError, PayloadType}; use meilisearch_types::error::{Code, ErrorCode, ResponseError}; +use meilisearch_types::index_uid::IndexUidFormatError; use serde_json::Value; use tokio::task::JoinError; @@ -24,6 +25,8 @@ pub enum MeilisearchHttpError { #[error("The provided payload reached the size limit.")] PayloadTooLarge, #[error(transparent)] + IndexUid(#[from] IndexUidFormatError), + #[error(transparent)] SerdeJson(#[from] serde_json::Error), #[error(transparent)] HeedError(#[from] meilisearch_types::heed::Error), @@ -50,6 +53,7 @@ impl ErrorCode for MeilisearchHttpError { MeilisearchHttpError::DocumentNotFound(_) => Code::DocumentNotFound, MeilisearchHttpError::InvalidExpression(_, _) => Code::Filter, MeilisearchHttpError::PayloadTooLarge => Code::PayloadTooLarge, + MeilisearchHttpError::IndexUid(e) => e.error_code(), MeilisearchHttpError::SerdeJson(_) => Code::Internal, MeilisearchHttpError::HeedError(_) => Code::Internal, MeilisearchHttpError::IndexScheduler(e) => e.error_code(), diff --git a/meilisearch-http/src/routes/indexes/documents.rs b/meilisearch-http/src/routes/indexes/documents.rs index 716b69862..dc07fd116 100644 --- a/meilisearch-http/src/routes/indexes/documents.rs +++ b/meilisearch-http/src/routes/indexes/documents.rs @@ -10,6 +10,7 @@ use log::debug; use meilisearch_types::document_formats::{read_csv, read_json, read_ndjson, PayloadType}; use meilisearch_types::error::ResponseError; use meilisearch_types::heed::RoTxn; +use meilisearch_types::index_uid::IndexUid; use meilisearch_types::milli::update::IndexDocumentsMethod; use meilisearch_types::star_or::StarOr; use meilisearch_types::tasks::KindWithContent; @@ -217,6 +218,9 @@ async fn document_addition( } }; + // is your indexUid valid? + let index_uid = IndexUid::try_from(index_uid)?.into_inner(); + let (uuid, mut update_file) = index_scheduler.create_update_file()?; // TODO: this can be slow, maybe we should spawn a thread? But the payload isn't Send+Sync :weary: diff --git a/meilisearch-types/src/index_uid.rs b/meilisearch-types/src/index_uid.rs index eb4f7768b..00e94c5b9 100644 --- a/meilisearch-types/src/index_uid.rs +++ b/meilisearch-types/src/index_uid.rs @@ -4,6 +4,8 @@ use std::str::FromStr; use serde::{Deserialize, Serialize}; +use crate::error::{Code, ErrorCode}; + /// An index uid is composed of only ascii alphanumeric characters, - and _, between 1 and 400 /// bytes long #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] @@ -82,3 +84,9 @@ impl fmt::Display for IndexUidFormatError { } impl Error for IndexUidFormatError {} + +impl ErrorCode for IndexUidFormatError { + fn error_code(&self) -> Code { + Code::InvalidIndexUid + } +}