rtk-ai/rtk · error

--stat -p must parse

Error message

--stat -p must parse

What it means

In test `git_stat_separator_and_format_b_prose_condense` (src/cmds/git/diff_cmd.rs:6376), `.expect("--stat -p must parse")` panics because `condense_unified_diff_strict` returned `None` for the fixture `tests/fixtures/diff/git_log_p_stat_raw.txt` (real `git log --stat -p` output). The stream contains a bare `---` separator between the commit message and the diffstat; the parser must treat it as a separator (not lost content) and produce `[file] i.py (+1 -1)` plus `[file] m.txt (mode changed)`.

Solutions

  1. Run `cargo test git_stat_separator_and_format_b_prose_condense -- --nocapture` to see whether the `--stat -p` or `--format=%B` block panics.
  2. Check the diffstat/`---`-separator handling in `condense_unified_diff_strict` (src/cmds/git/diff_cmd.rs:2083): a bare `---` before diffstat lines must not mark content as lost or abort parsing.
  3. Verify the GNU latch logic treats commit-body prose starting with `diff ` as prose (does not re-arm the raw passthrough).
  4. Add minimal inline inputs (message + `---` + diffstat; body prose `diff ...` + real hunk) so both shapes stay covered.

Example fix

// before
let out = condense_unified_diff_strict(stat).expect("--stat -p must parse");
// after
let out = condense_unified_diff_strict(stat)
    .unwrap_or_else(|| panic!("--stat -p fixture fell back raw:\n{stat}"));
Defensive patterns

Strategy: validation

Validate before calling

let stat = include_str!("tests/fixtures/diff/git_log_p_stat_raw.txt");
assert!(condense_unified_diff_strict(stat).is_some(), "--stat -p stream must parse");

Type guard

fn condenses(diff: &str) -> bool { condense_unified_diff_strict(diff).is_some() }

Try / catch

let out = condense_unified_diff_strict(stat)
    .unwrap_or_else(|| panic!("--stat -p fixture fell back raw:\n{stat}"));

Prevention

When it happens

Trigger: Running `cargo test git_stat_separator_and_format_b_prose_condense`: parsing `git log --stat -p` capture with the bare `---` separator, or the paired `git show --format=%B` capture whose body prose begins with `diff `. Either shape returning `None` triggers the panic at line 6380 (or the analogous `--format=%B` expect a few lines below).

Common situations: Edits to how the parser handles diffstat sections (`file | N +-` lines) or the bare `---` divider; changes to the GNU 'latch' arming logic that made prose starting with `diff ` re-arm or disarm incorrectly and reject the stream; new guards for commit-message regions that are too strict and bail on the whole input.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19). Data as JSON: /api/errors/b5f82cb4b26cb516. Report an issue: GitHub.

Appendix: source

Thrown at src/cmds/git/diff_cmd.rs:6380

        let fixture = include_str!("../../../tests/fixtures/diff/git_diff_latin1_raw.txt");
        let out = condense_unified_diff_strict(fixture).expect("must parse");
        assert!(
            out.contains("[file] \"caf\\350.txt\" (+1 -1)"),
            "got:\n{out}"
        );
        assert!(
            out.contains("[file] \"caf\\351.txt\" (+1 -1)"),
            "got:\n{out}"
        );
        assert!(!out.contains('\u{FFFD}'), "got:\n{out}");
    }

    #[test]
    fn git_stat_separator_and_format_b_prose_condense() {
        // Real `git log --stat -p`: a bare `---` between the message and
        // the diffstat used to read as lost content.
        let stat = include_str!("../../../tests/fixtures/diff/git_log_p_stat_raw.txt");
        let out = condense_unified_diff_strict(stat).expect("--stat -p must parse");
        assert!(out.contains("[file] i.py (+1 -1)"), "got:\n{out}");
        assert!(out.contains("[file] m.txt (mode changed)"), "got:\n{out}");
        // Real `git show --format=%B`: body prose starting with `diff `
        // used to arm the GNU latch and send the stream raw.
        let b = include_str!("../../../tests/fixtures/diff/git_show_format_B_raw.txt");
        let out = condense_unified_diff_strict(b).expect("--format=%B must parse");
        assert_eq!(out, "[file] w.txt (+1 -0)\n+zz");
    }

    #[test]
    fn combined_diffs_with_three_parents_parse() {
        // Real octopus merge: `@@@@` with three old ranges, via `git show
        // --cc` and via `git diff-tree -c` (`diff --combined`).
        for fixture in [
            include_str!("../../../tests/fixtures/diff/git_show_cc_octopus_raw.txt"),
            include_str!("../../../tests/fixtures/diff/git_diff_tree_combined_raw.txt"),
        ] {
            let out = condense_unified_diff_strict(fixture).expect("must parse");

View on GitHub (pinned to 0924356b4c)