{"record":{"id":"215db03cb7d64aa8","repo":"Hmbown/CodeWhale","slug":"no-patch-file-provided-and-stdin-is-empty","errorCode":null,"errorMessage":"No patch file provided and stdin is empty.","messagePattern":"No patch file provided and stdin is empty\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9938,"sourceCode":"        .output()\n        .map_err(|e| anyhow::anyhow!(\"Failed to run git apply: {e}\"))?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        bail!(\"git apply failed: {}\", stderr.trim());\n    }\n    println!(\"Applied patch successfully.\");\n    Ok(())\n}\n\n/// Maximum bytes read for a patch on stdin. Generous for large diffs;\n/// anything larger is not a patch.\nconst MAX_STDIN_PATCH_BYTES: u64 = 16 * 1024 * 1024;\n\nfn read_patch_from_stdin() -> Result<String> {\n    let stdin = io::stdin();\n    if stdin.is_terminal() {\n        bail!(\"No patch file provided and stdin is empty.\");\n    }\n    let mut buffer = String::new();\n    stdin\n        .take(MAX_STDIN_PATCH_BYTES + 1)\n        .read_to_string(&mut buffer)?;\n    if buffer.len() as u64 > MAX_STDIN_PATCH_BYTES {\n        bail!(\"patch on stdin exceeds the 16 MiB limit\");\n    }\n    Ok(buffer)\n}\n\nasync fn run_mcp_command(\n    config: &Config,\n    workspace: &Path,\n    command: McpCommand,\n    plugins: &crate::plugins::PluginRegistry,\n) -> Result<()> {\n    let config_path = config.mcp_config_path();","sourceCodeStart":9920,"sourceCodeEnd":9956,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9920-L9956","documentation":"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.","triggerScenarios":"Running the apply command with neither --patch nor piped stdin — stdin is an interactive TTY, so `is_terminal()` is true.","commonSituations":"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.","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"],"exampleFix":"// before\ncodewhale apply            # stdin is a TTY\n// after\ngit diff | codewhale apply","handlingStrategy":"validation","validationCode":"use std::io::IsTerminal;\nif std::io::stdin().is_terminal() && patch_path.is_none() { /* error: no patch source; require --patch or a pipe */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cli","patch","stdin","missing-input"],"backgroundTag":"missing-cli-argument","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}