From 0cca2ea24fccb701d8897e7430f20f455984cac9 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 22 Jun 2021 11:22:33 +0200 Subject: [PATCH 1/2] Return a MissingDocumentId when a document doesn't have one --- milli/src/update/index_documents/transform.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/milli/src/update/index_documents/transform.rs b/milli/src/update/index_documents/transform.rs index d4a730fcc..24ab276d0 100644 --- a/milli/src/update/index_documents/transform.rs +++ b/milli/src/update/index_documents/transform.rs @@ -18,7 +18,7 @@ use crate::index::db_name; use crate::update::index_documents::merge_function::{keep_latest_obkv, merge_obkvs}; use crate::update::{AvailableDocumentsIds, UpdateIndexingStep}; use crate::{ - ExternalDocumentsIds, FieldId, FieldDistribution, FieldsIdsMap, Index, MergeFn, Result, BEU32, + ExternalDocumentsIds, FieldDistribution, FieldId, FieldsIdsMap, Index, MergeFn, Result, BEU32, }; const DEFAULT_PRIMARY_KEY_NAME: &str = "id"; @@ -190,7 +190,7 @@ impl Transform<'_, '_> { }, None => { if !self.autogenerate_docids { - return Err(UserError::MissingPrimaryKey.into()); + return Err(UserError::MissingDocumentId { document }.into()); } let uuid = uuid::Uuid::new_v4().to_hyphenated().encode_lower(&mut uuid_buffer); Cow::Borrowed(uuid) From aecbd1476138fbf18e072b911509c294d96434d7 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 22 Jun 2021 11:31:58 +0200 Subject: [PATCH 2/2] Improve the error message for InvalidDocumentId --- milli/src/error.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/milli/src/error.rs b/milli/src/error.rs index 31012c690..d927407f0 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -206,7 +206,13 @@ impl fmt::Display for UserError { Self::InvalidCriterionName { name } => write!(f, "invalid criterion {}", name), Self::InvalidDocumentId { document_id } => { let json = serde_json::to_string(document_id).unwrap(); - write!(f, "document identifier is invalid {}", json) + write!( + f, + "document identifier is invalid {}, \ +a document id can be of type integer or string \ +only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and underscores (_)", + json + ) } Self::InvalidFilterAttribute(error) => error.fmt(f), Self::MissingDocumentId { document } => {