This commit is contained in:
Clément Renault 2022-10-20 17:24:15 +02:00
parent 4c42130ec7
commit ca8c922f35
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -44,15 +44,23 @@ impl Display for DocumentFormatError {
// The user input maybe insanely long. We need to truncate it. // The user input maybe insanely long. We need to truncate it.
let mut serde_msg = se.to_string(); let mut serde_msg = se.to_string();
let ellipsis = "..."; let ellipsis = "...";
if serde_msg.len() > 100 + ellipsis.len() { let trim_input_prefix_len = 50;
serde_msg.replace_range(50..serde_msg.len() - 85, ellipsis); 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!( write!(
f, f,
"The `{}` payload provided is malformed. `Couldn't serialize document value: {}`.", "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), _ => write!(f, "The `{}` payload provided is malformed: `{}`.", b, me),
}, },