format_serde_error icon indicating copy to clipboard operation
format_serde_error copied to clipboard

Panic on small characters count

Open Veetaha opened this issue 4 years ago • 1 comments

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

Veetaha avatar Mar 12 '22 21:03 Veetaha

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!

webbrain-one avatar Aug 05 '26 10:08 webbrain-one