From ca8c922f359b084a3a7589c8abc1e5a4c3fad9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 20 Oct 2022 17:24:15 +0200 Subject: [PATCH] Reapply #2727 --- meilisearch-types/src/document_formats.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/meilisearch-types/src/document_formats.rs b/meilisearch-types/src/document_formats.rs index 5a50bfc0f..17c01789e 100644 --- a/meilisearch-types/src/document_formats.rs +++ b/meilisearch-types/src/document_formats.rs @@ -44,15 +44,23 @@ impl Display for DocumentFormatError { // The user input maybe insanely long. We need to truncate it. let mut serde_msg = se.to_string(); let ellipsis = "..."; - if serde_msg.len() > 100 + ellipsis.len() { - serde_msg.replace_range(50..serde_msg.len() - 85, ellipsis); + let trim_input_prefix_len = 50; + let trim_input_suffix_len = 85; + + if serde_msg.len() + > trim_input_prefix_len + trim_input_suffix_len + ellipsis.len() + { + serde_msg.replace_range( + trim_input_prefix_len..serde_msg.len() - trim_input_suffix_len, + ellipsis, + ); } write!( f, "The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.", b, serde_msg - ) + ) } _ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me), },