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
The patch-apply command falls back to reading the patch from stdin when no --patch file is given. If stdin is a terminal (nothing is piped in), there is no patch source, so it bails with this message rather than hanging on a read.
Solutions
- Pipe the patch in: `git diff | codewhale apply` or `codewhale apply < p.diff`
- Pass a file explicitly: `codewhale apply --patch p.diff`
- Fix the script wrapper so stdin is forwarded to the command
Example fix
// before codewhale apply # stdin is a TTY // after git diff | codewhale apply
Defensive patterns
Strategy: validation
Validate before calling
use std::io::IsTerminal;
if std::io::stdin().is_terminal() && patch_path.is_none() { /* error: no patch source; require --patch or a pipe */ } Prevention
- Always pipe a patch or pass --patch; never run apply bare interactively
- In scripts, assert stdin is not a TTY (`[ ! -t 0 ]`) before invoking
- Forward stdin through wrappers/subshells
When it happens
Trigger: Running the apply command with neither --patch nor piped stdin — stdin is an interactive TTY, so `is_terminal()` is true.
Common situations: Forgetting to pipe a patch: running `codewhale apply` bare in a shell; pasting into CI scripts where the pipe was dropped; wrapping the command in a way that detaches stdin.
Understand the failure class
Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.
Related errors
- patch on stdin exceeds the 16 MiB limit
- API key input is unexpectedly large
- API key on stdin exceeds the 8 KiB limit
- external credential consent was not saved: non-interactive…
- git apply failed
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/215db03cb7d64aa8.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/lib.rs:9938
.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(())
}
/// Maximum bytes read for a patch on stdin. Generous for large diffs;
/// anything larger is not a patch.
const MAX_STDIN_PATCH_BYTES: u64 = 16 * 1024 * 1024;
fn read_patch_from_stdin() -> Result<String> {
let stdin = io::stdin();
if stdin.is_terminal() {
bail!("No patch file provided and stdin is empty.");
}
let mut buffer = String::new();
stdin
.take(MAX_STDIN_PATCH_BYTES + 1)
.read_to_string(&mut buffer)?;
if buffer.len() as u64 > MAX_STDIN_PATCH_BYTES {
bail!("patch on stdin exceeds the 16 MiB limit");
}
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();View on GitHub (pinned to 73e0f67d83)