rtk-ai/rtk · error
--format=%B must parse
Error message
--format=%B must parse
What it means
The test `git_show_format_B` in src/cmds/git/diff_cmd.rs calls `condense_unified_diff_strict(b).expect("--format=%B must parse")`. `condense_unified_diff_strict` (diff_cmd.rs:2083) returns `Option<String>` and yields `None` whenever the strict unified-diff state machine decides a stream is not a parseable diff (unsupported line shapes, prose misclassification, unterminated regions). The panic means the strict parser rejected the `git show --format=%B` fixture instead of condensing it to `[file] w.txt (+1 -0)`. The fixture's body prose starting with `diff ` is designed to exercise the GNU-latch rules; a parser regression re-arms the latch and the stream is sent raw or rejected.
Solutions
- Run `cargo test git_show_format_B` with a debug print inside condense_unified_diff_strict to find the line where parsing bails to None
- Check the GNU latch (`gnu_diff_r`) state transitions around the `diff ` line in the fixture message body
- Verify the fixture still matches real `git show --format=%B` output; regenerate with `git show --format=%B <sha>` if it drifted
- Diff recent commits touching diff_cmd.rs rules 5/8 and revert the offending state-machine change
Example fix
// before
let out = condense_unified_diff_strict(b).expect("--format=%B must parse");
// after (diagnosing, keep expect in final code)
let out = match condense_unified_diff_strict(b) {
Some(o) => o,
None => panic!("strict parser returned None for git_show_format_B fixture"),
}; Defensive patterns
Strategy: try-catch
Validate before calling
// Before running the full suite, check the fixture still parses:
let b = include_str!("../../../tests/fixtures/diff/git_show_format_B_raw.txt");
if condense_unified_diff_strict(b).is_none() {
eprintln!("git_show_format_B fixture no longer parses");
} Try / catch
// Isolate the failure with a descriptive panic instead of a bare expect:
let out = condense_unified_diff_strict(b).unwrap_or_else(||
panic!("strict parser returned None for git_show_format_B_raw fixture")); Prevention
- When touching diff_cmd.rs parser rules, run the diff test module (`cargo test diff_cmd`) before committing
- Keep fixtures generated from real tool output and re-verify them when bumping git/diffutils versions
- Add temporary eprintln! tracing at every None bail-out in condense_unified_diff_strict when debugging
- Cover each parser rule (mbox, GNU latch, no-index) with at least one fixture test so regressions are localized
When it happens
Trigger: Running `cargo test` when condense_unified_diff_strict returns None for tests/fixtures/diff/git_show_format_B_raw.txt. Happens after edits to the parser's GNU latch, mbox message region, or file-header recognition rules in diff_cmd.rs.
Common situations: A contributor refactors the diff condensing rules and breaks recognition of `git show --format=%B` output whose commit body contains a line starting with `diff `; a fixture is regenerated with content the strict parser no longer accepts.
Related errors
- --stat -p must parse
- a bodyless region of prose must not force raw
- a table in the message must not force raw
- f.txt entry
- filter(s) have no inline tests (use --require-all in CI)
AI-assisted analysis of rtk-ai/rtk@0924356b4c (2026-09-19).
Data as JSON: /api/errors/3d76e1109b5ef41e.
Report an issue: GitHub.
Appendix: source
Thrown at src/cmds/git/diff_cmd.rs:6386
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");
assert_eq!(out, "[file] x.txt (+1 -1)\n---2\n+++EVIL");
}
}
#[test]
fn svn_copy_target_without_content_is_listed() {View on GitHub (pinned to 0924356b4c)