From 60792eebcf33785126f10e9e054638405b3a0e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wi=C5=9Bniewski?= Date: Wed, 31 Aug 2022 19:29:53 +0200 Subject: [PATCH 1/3] Fix #2207 - do not panic when the error message length is between 100 and 135 --- meilisearch-lib/src/document_formats.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch-lib/src/document_formats.rs b/meilisearch-lib/src/document_formats.rs index ebc98f3fb..be48c9bbf 100644 --- a/meilisearch-lib/src/document_formats.rs +++ b/meilisearch-lib/src/document_formats.rs @@ -44,7 +44,7 @@ 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() { + if serde_msg.len() > (50 + 85) + ellipsis.len() { serde_msg.replace_range(50..serde_msg.len() - 85, ellipsis); } From d1b364292322028d4ea4fea820b70c13a3bac222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wi=C5=9Bniewski?= Date: Thu, 1 Sep 2022 20:50:11 +0200 Subject: [PATCH 2/3] Extract input to trim lengths to variables --- meilisearch-lib/src/document_formats.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/meilisearch-lib/src/document_formats.rs b/meilisearch-lib/src/document_formats.rs index be48c9bbf..a0b3c0552 100644 --- a/meilisearch-lib/src/document_formats.rs +++ b/meilisearch-lib/src/document_formats.rs @@ -44,8 +44,15 @@ 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() > (50 + 85) + 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!( @@ -136,9 +143,14 @@ pub fn read_json(input: impl Read, writer: impl Write + Seek) -> Result { let content: ArrayOrSingleObject = serde_json::from_reader(reader) .map_err(Error::Json) - .map_err(|e| (PayloadType::Json, e))?; + .map_err(|e| { + println!("Błąd o taki: {:#?}", e); + (PayloadType::Json, e) + })?; + println!("content o taki: {:#?}", content); for object in content.inner.map_right(|o| vec![o]).into_inner() { + println!("{:#?}", object); builder .append_json_object(&object) .map_err(Into::into) @@ -146,6 +158,8 @@ pub fn read_json(input: impl Read, writer: impl Write + Seek) -> Result { } let count = builder.documents_count(); + println!("{count}"); + let _ = builder .into_inner() .map_err(Into::into) From d1a30df23da0368b2a5f9695230eabc25c95db14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Wi=C5=9Bniewski?= Date: Wed, 7 Sep 2022 18:05:55 +0200 Subject: [PATCH 3/3] Remove unneeded prints, format --- meilisearch-lib/src/document_formats.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/meilisearch-lib/src/document_formats.rs b/meilisearch-lib/src/document_formats.rs index a0b3c0552..83e5b9fdb 100644 --- a/meilisearch-lib/src/document_formats.rs +++ b/meilisearch-lib/src/document_formats.rs @@ -47,7 +47,8 @@ impl Display for DocumentFormatError { 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() + 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, @@ -143,14 +144,9 @@ pub fn read_json(input: impl Read, writer: impl Write + Seek) -> Result { let content: ArrayOrSingleObject = serde_json::from_reader(reader) .map_err(Error::Json) - .map_err(|e| { - println!("Błąd o taki: {:#?}", e); - (PayloadType::Json, e) - })?; + .map_err(|e| (PayloadType::Json, e))?; - println!("content o taki: {:#?}", content); for object in content.inner.map_right(|o| vec![o]).into_inner() { - println!("{:#?}", object); builder .append_json_object(&object) .map_err(Into::into) @@ -158,8 +154,6 @@ pub fn read_json(input: impl Read, writer: impl Write + Seek) -> Result { } let count = builder.documents_count(); - println!("{count}"); - let _ = builder .into_inner() .map_err(Into::into)