{"record":{"id":"79e70e586e6e482a","repo":"Hmbown/CodeWhale","slug":"patch-is-empty","errorCode":null,"errorMessage":"Patch is empty.","messagePattern":"Patch is empty\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9908,"sourceCode":"    } else {\n        \"working-tree\".to_string()\n    };\n    if let Some(path) = &args.path {\n        label.push(' ');\n        label.push_str(path.to_string_lossy().as_ref());\n    }\n    label\n}\n\nfn run_apply(args: ApplyArgs) -> Result<()> {\n    let patch = if let Some(path) = args.patch_file {\n        std::fs::read_to_string(&path)\n            .map_err(|e| anyhow::anyhow!(\"Failed to read patch {}: {}\", path.display(), e))?\n    } else {\n        read_patch_from_stdin()?\n    };\n    if patch.trim().is_empty() {\n        bail!(\"Patch is empty.\");\n    }\n\n    let mut tmp = NamedTempFile::new()?;\n    tmp.write_all(patch.as_bytes())?;\n    let tmp_path = tmp.path().to_path_buf();\n\n    let output = crate::dependencies::Git::command()\n        .ok_or_else(|| anyhow::anyhow!(\"git not found on PATH\"))?\n        .arg(\"apply\")\n        .arg(\"--whitespace=nowarn\")\n        .arg(&tmp_path)\n        .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    }","sourceCodeStart":9890,"sourceCodeEnd":9926,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9890-L9926","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Check the patch source actually contains a diff (`cat patch.diff | head`); regenerate it if empty","Verify you passed the intended file to --patch, not an empty placeholder","If piping, confirm the upstream command emitted a diff before piping (e.g. `git diff HEAD~1 > p.diff`)"],"exampleFix":"// before\ncodewhale apply --patch p.diff   # p.diff is 0 bytes\n// after\ngit diff HEAD~1 > p.diff && codewhale apply --patch p.diff","handlingStrategy":"validation","validationCode":"let patch = std::fs::read_to_string(path)?;\nif patch.trim().is_empty() { /* refuse: regenerate the patch */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify patch files are non-empty (ls -la / head) before passing --patch","Regenerate patches from a real diff, never from an empty command's output","Don't create patch files with `> p.diff` without redirecting content into them"],"tags":["cli","patch","validation","empty-input"],"backgroundTag":"empty-required-field","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"}