bugger.
All challenges/Rusthardthe-error-that-keeps-coming-v1
THE INVESTIGATION

The error that keeps coming

A streaming log collector counts one rejected record several times, depending on network packet boundaries.

StreamingState machinesError recoveryBoundary conditions

What’s going wrong

A log collector rejects oversized records and then recovers at the next newline. Monitoring reports several errors for one bad record when it arrives across multiple network reads. The same bytes sent in one read may look fine.

The first input line is the maximum record length, an integer from 0 through 4096. Each subsequent line is one network read encoded as an even number of hexadecimal digits, or `-` for an empty read. Concatenate the decoded reads to obtain the wire stream; hexadecimal letter case is irrelevant. Total decoded input is at most 16384 bytes.

Records end at byte 0a (LF). The length limit counts all bytes before LF, including a trailing 0d (CR). An in-limit record emits `LINE:` followed by its bytes as lowercase hex, removing one trailing CR only when an LF terminates it. Empty LF-terminated records are valid. Once an unfinished record exceeds the limit, emit exactly one `ERROR` immediately and discard that record through its LF, even across reads. Resume normally with the next record, including one already in the same read. At end of input, emit a nonempty in-limit unterminated record without stripping CR; discard an already rejected tail without another error. A final LF creates no extra empty record.

Print one JSON array of event strings in stream order. Repair the decoder while preserving this protocol. Packet boundaries must not change the final events.

Expected behavior

Each oversized logical record produces one error, discarded bytes cannot become records, and decoding resumes after its delimiter without losing later valid records.

Reproduction

01 One rejected record across three reads
4
616263646566
6768696a6b
0a6f6b0a
["ERROR","LINE:6f6b"]
02 Ordinary fragmented records
4
6162
630a78790a
["LINE:616263","LINE:7879"]
03 Oversized record and recovery in one read
4
61626364650a6f6b0a
["ERROR","LINE:6f6b"]

Before you begin

  • Rust enums and mutable state
  • Byte buffers and delimiters
  • Incremental parsing and recovery

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.