From b28aa8e66600d57b4b51e51dfec8549dab605185 Mon Sep 17 00:00:00 2001 From: LiuHanCheng <2463765697@qq.com> Date: Thu, 31 Mar 2022 10:14:13 +0800 Subject: [PATCH] Update meilisearch-lib/src/document_formats.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Renault --- meilisearch-lib/src/document_formats.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/meilisearch-lib/src/document_formats.rs b/meilisearch-lib/src/document_formats.rs index 424313c8c..27097a81b 100644 --- a/meilisearch-lib/src/document_formats.rs +++ b/meilisearch-lib/src/document_formats.rs @@ -39,22 +39,15 @@ impl Display for DocumentFormatError { // https://github.com/meilisearch/meilisearch/issues/2107 // The user input maybe insanely long. We need to truncate it. let mut serde_msg = se.to_string(); - let prefix = r#"invalid type: string ""#; - if serde_msg.starts_with(prefix) { - let start_idx = prefix.len(); - if let Some(end_idx) = serde_msg.rfind("\"") { - if end_idx - start_idx > 100 { - serde_msg.replace_range(start_idx + 50..end_idx - 50, " ... "); - } - } else { - serde_msg = String::from(""); - } + let ellipsis = "..."; + if serde_msg.len() > 100 + ellipsis.len() { + serde_msg.replace_range(50..serde_msg.len() - 50, ellipsis); } write!( - f, - "The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.", - b,serde_msg + f, + "The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.", + b, serde_msg ) } _ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me),