Hmbown/CodeWhale · error · anyhow::Error
Patch is empty.
Error message
Patch is empty.
What it means
run_apply reads the patch from --patch-file or stdin and refuses it before invoking git when the content is empty after trimming. It is an input guard: an all-whitespace patch is always a caller mistake (bad pipe, wrong file, empty model output), and applying it would be a no-op at best.
Source
Thrown at crates/tui/src/lib.rs:8419
} else {
"working-tree".to_string()
};
if let Some(path) = &args.path {
label.push(' ');
label.push_str(path.to_string_lossy().as_ref());
}
label
}
fn run_apply(args: ApplyArgs) -> Result<()> {
let patch = if let Some(path) = args.patch_file {
std::fs::read_to_string(&path)
.map_err(|e| anyhow::anyhow!("Failed to read patch {}: {}", path.display(), e))?
} else {
read_patch_from_stdin()?
};
if patch.trim().is_empty() {
bail!("Patch is empty.");
}
let mut tmp = NamedTempFile::new()?;
tmp.write_all(patch.as_bytes())?;
let tmp_path = tmp.path().to_path_buf();
let output = crate::dependencies::Git::command()
.ok_or_else(|| anyhow::anyhow!("git not found on PATH"))?
.arg("apply")
.arg("--whitespace=nowarn")
.arg(&tmp_path)
.output()
.map_err(|e| anyhow::anyhow!("Failed to run git apply: {e}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
bail!("git apply failed: {}", stderr.trim());
}View on GitHub (pinned to 0c42157ee5)
Solutions
- Inspect the file: `wc -c patch.diff` and `head patch.diff`
- Regenerate the patch at its source (re-run the tool/model that produced it)
- If piping, check the producer's exit status and output before applying
- Confirm the path is a file, not a directory or wrong name
Example fix
# before
codewhale apply --patch-file empty.diff # Patch is empty.
# after
[ -s patch.diff ] || { echo 'producer wrote nothing'; exit 1; }
codewhale apply --patch-file patch.diff Defensive patterns
Strategy: validation
Validate before calling
[ -s "$PATCH" ] && [ -n "$(tr -d '[:space:]' < "$PATCH")" ] || { echo "patch '$PATCH' is empty"; exit 1; } Try / catch
if let Err(e) = run_apply(args) {
if e.to_string().contains("Patch is empty") {
// regenerate at the source; do not retry the same input
}
} Prevention
- Use `set -euo pipefail` so a failed diff producer aborts before apply
- Check `[ -s file ]` before passing --patch-file
- Validate that model/tool output actually contains a non-empty diff before saving it
When it happens
Trigger: --patch-file points at an empty or whitespace-only file; stdin piped from a producer that wrote nothing; the model/tool upstream returned an empty diff block that was saved to disk.
Common situations: LLM answered with prose instead of a diff and the pipeline saved the empty fenced block; upstream generate step failed silently because the script lacks `set -e`; truncated download or wrong file path.
Related errors
- git apply failed: {}
- No patch file provided and stdin is empty.
- host cannot be empty
- continual harness entry id cannot be empty
- Agent Mail accepts a bounded handoff summary, not a raw tran
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/79e70e586e6e482a.
Report an issue: GitHub.