Hmbown/CodeWhale · error · anyhow::Error

No patch file provided and stdin is empty.

Error message

No patch file provided and stdin is empty.

What it means

When no --patch-file is given, read_patch_from_stdin reads the patch from stdin -- but it bails immediately if stdin is a terminal (is_terminal()). Despite the wording, the check is 'stdin is a TTY', not 'stdin has no bytes': the guard stops the command from hanging while a human types. In non-TTY contexts an empty pipe is instead caught by the 'Patch is empty.' check.

Source

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

        .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());
    }
    println!("Applied patch successfully.");
    Ok(())
}

fn read_patch_from_stdin() -> Result<String> {
    let mut stdin = io::stdin();
    if stdin.is_terminal() {
        bail!("No patch file provided and stdin is empty.");
    }
    let mut buffer = String::new();
    stdin.read_to_string(&mut buffer)?;
    Ok(buffer)
}

async fn run_mcp_command(
    config: &Config,
    workspace: &Path,
    command: McpCommand,
    plugins: &crate::plugins::PluginRegistry,
) -> Result<()> {
    let config_path = config.mcp_config_path();
    match command {
        McpCommand::Init { force } => {
            let status = init_mcp_config(&config_path, force)?;
            match status {
                WriteStatus::Created => {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Pipe the patch: `codewhale apply < patch.diff` or `producer | codewhale apply`
  2. Or pass `--patch-file patch.diff`
  3. In scripts, always redirect stdin explicitly (`</dev/null` when unused)

Example fix

# before
codewhale apply            # No patch file provided and stdin is empty.

# after
codewhale apply < fix.diff
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$PATCH_FILE" ] && [ -t 0 ]; then echo 'pass --patch-file or pipe a patch on stdin'; exit 1; fi
codewhale apply ${PATCH_FILE:+--patch-file "$PATCH_FILE"}

Prevention

When it happens

Trigger: Running `codewhale apply` bare in an interactive shell; a wrapper that allocates a pseudo-TTY (expect, some CI steps) but supplies no patch.

Common situations: Forgetting the pipe or flag; docs example only half copy-pasted; running under a pty wrapper that makes stdin look interactive.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20). Data as JSON: /api/errors/215db03cb7d64aa8. Report an issue: GitHub.