format_serde_error
format_serde_error copied to clipboard
Panic on small characters count
The following test fails:
#[test]
fn sandbox() {
let input = r#"[
[1],
[2],
[3],
[4],
[1, 2, 3, 4, -5],
[6]
]"#;
let err = serde_json::from_str::<Vec<Vec<u32>>>(input).unwrap_err();
let mut err = format_serde_error::SerdeError::new(input.to_owned(), err);
err.set_context_characters(9);
// This doesn't panic, but doesn't seem to properly limit columns to 10 either?
// err.set_context_characters(10);
// This panics
err.to_string();
}
Note that indentation matters very much here, so make sure to copy this code with care preserving all the whitespace
Expected behavior
Since there is nothing in the documentation for set_context_characters input limits I assume that any usize value from 0 to usize::MAX must not produce panic
Hi there! 👋
I've opened a pull request to address this issue: https://github.com/AlexanderThaller/format_serde_error/pull/26
This fix resolves the panic that occurs when set_context_characters is set to a small number. It ensures the logic handles smaller context sizes gracefully without crashing.
Thanks for reporting this!