Update meilisearch-lib/src/document_formats.rs

Co-authored-by: Clément Renault <renault.cle@gmail.com>
This commit is contained in:
LiuHanCheng 2022-03-31 10:14:13 +08:00 committed by GitHub
parent 13a0e78d3f
commit b28aa8e666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
b, serde_msg
)
}
_ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me),