Hmbown/CodeWhale · error
Incomplete PR diff: a file patch is missing
Error message
Incomplete PR diff: a file patch is missing
What it means
While scanning the diff, complete_file_set requires every `diff --git <a> <b>` file header to be followed by an actual patch body (a valid @@ hunk or binary metadata). When a new file header appears while the previous file (files > 0) never produced has_patch, the previous file's patch is missing entirely and the review aborts.
Solutions
- Re-run with plain git diff options: `git diff --no-ext-diff --no-color base...head` and confirm every `diff --git` header has a following `index`/hunk body
- Check that the file count in the error matches view.changed_files; if fewer, the fetch truncated and the diff must be re-fetched completely
- Disable external diff/renames filters for the review path (the tool already passes --no-ext-diff; ensure no repo config overrides it via diff.external)
Example fix
// before: repo config with an external diff driver git config diff.external /usr/bin/custom-diff // after: unset it so --no-ext-diff has nothing to override git config --unset diff.external
Defensive patterns
Strategy: validation
Validate before calling
// every 'diff --git' header must be followed by an 'index' line
let lines: Vec<&str> = diff.lines().collect();
for (i, l) in lines.iter().enumerate() {
if l.starts_with("diff --git ") {
assert!(lines.get(i + 1).map_or(false, |n| n.starts_with("index ")), "file patch missing after header at line {}");
}
} Try / catch
match diff_with(&view) {
Err(e) if e.to_string().contains("file patch is missing") => eprintln!("refetch complete diff; check output limits and external diff drivers"),
other => other?,
} Prevention
- Unset diff.external / diff.<driver>.command in the review checkout
- Raise any output truncation limits used by the wrapping process
- Verify fetched diff contains exactly view.changed_files 'diff --git' headers
When it happens
Trigger: A `diff --git` header is present but its body was dropped — e.g. truncation removed everything after the header, or `git diff` was run with flags limiting per-file output for a file that changed.
Common situations: Very large diffs clipped by output limits; renames/mode-only changes filtered out by diff options; external diff drivers suppressing output for specific file types; corrupted tool output pipelines.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Incomplete PR diff: a text hunk is truncated or malformed
- Incomplete PR diff: received
- PR diff contains binary metadata without exact full object…
- Incomplete PR diff: malformed hunk header
- A full Git history is required to establish the PR merge…
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/7157ff795ac91ddd.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/tools/review_pr.rs:197
remaining.1 -= 1;
additions += 1;
}
Some(b'-') if remaining.0 > 0 => {
remaining.0 -= 1;
deletions += 1;
}
Some(b' ') if remaining.0 > 0 && remaining.1 > 0 => {
remaining.0 -= 1;
remaining.1 -= 1;
}
Some(b'\\') => {}
_ => bail!("Incomplete PR diff: a text hunk is truncated or malformed"),
}
continue;
}
if line.starts_with("diff --git ") {
if files > 0 && !has_patch {
bail!("Incomplete PR diff: a file patch is missing");
}
files += 1;
has_patch = false;
has_full_index = false;
} else if line.starts_with("index ") {
has_full_index = full_index_objects(line);
} else if let Some((_, old, new)) = super::review_hunks::parse_hunk_header(line) {
remaining = (old, new);
has_patch = true;
} else if line.starts_with("@@") {
bail!("Incomplete PR diff: malformed hunk header");
} else if [
"new file mode ",
"deleted file mode ",
"old mode ",
"new mode ",
"rename from ",
"rename to ",View on GitHub (pinned to 73e0f67d83)