Hmbown/CodeWhale · error · anyhow::Error

Patch is empty.

Error message

Patch is empty.

What it means

The patch-apply command reads a patch from a file (--patch path) or stdin and validates it is non-blank before staging it into a temp file for `git apply`. An empty/whitespace-only patch cannot be applied, so it bails immediately with this message.

Solutions

  1. Check the patch source actually contains a diff (`cat patch.diff | head`); regenerate it if empty
  2. Verify you passed the intended file to --patch, not an empty placeholder
  3. If piping, confirm the upstream command emitted a diff before piping (e.g. `git diff HEAD~1 > p.diff`)

Example fix

// before
codewhale apply --patch p.diff   # p.diff is 0 bytes
// after
git diff HEAD~1 > p.diff && codewhale apply --patch p.diff
Defensive patterns

Strategy: validation

Validate before calling

let patch = std::fs::read_to_string(path)?;
if patch.trim().is_empty() { /* refuse: regenerate the patch */ }

Prevention

When it happens

Trigger: The --patch file exists but contains only whitespace, or the piped stdin produced an empty string (e.g. an upstream command that failed silently and wrote nothing).

Common situations: Pointing --patch at an empty or truncated file (download interrupted, `> patch.diff` created but never written); piping the output of a command that produced no diff, like `git diff` between identical refs.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/79e70e586e6e482a. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lib.rs:9908

    } 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 73e0f67d83)