rust parsing_error ai_generated true

Err(Incomplete(Size(1)))

ID: rust/rust-nom-parse-incomplete

Also available as: JSON · Markdown
84%Fix Rate
86%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Nom's streaming parsers return Incomplete when they need more input. Use complete parsers or provide all input at once.

generic

Workarounds

  1. 90% success Use nom::complete combinators instead of nom::streaming
    // Instead of:
    use nom::bytes::streaming::tag;
    // Use:
    use nom::bytes::complete::tag;

    Sources: https://docs.rs/nom/latest/nom/bytes/complete/index.html

  2. 85% success Buffer all input before parsing when using streaming mode
    let full_input = std::io::read_to_string(reader)?;
    let result = parser(&full_input);

    Sources: https://docs.rs/nom/latest/nom/#streaming--complete

Dead Ends

Common approaches that don't work:

  1. Pad input with extra bytes to satisfy the size requirement 85% fail

    Extra bytes corrupt the parse result; the parser needs valid data, not padding

Error Chain

Leads to:
Preceded by:
Frequently confused with: