{"record":{"id":"1d8ed6f473f572a7","repo":"Hmbown/CodeWhale","slug":"failed-to-read-patch","errorCode":null,"errorMessage":"Failed to read patch {}: {}","messagePattern":"Failed to read patch (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/lib.rs","lineNumber":9903,"sourceCode":"        .as_deref()\n        .map(str::trim)\n        .filter(|base| !base.is_empty())\n    {\n        format!(\"base:{base}\")\n    } 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}\"))?;","sourceCodeStart":9885,"sourceCodeEnd":9921,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/lib.rs#L9885-L9921","documentation":"Raised by `run_apply` when the `--patch-file` path supplied to the apply command cannot be read with `std::fs::read_to_string`. It wraps the io::Error and includes the file path, so it covers nonexistent files, permission errors, and (via UTF-8 loss) non-UTF-8 content is tolerated but read failures abort. Without a patch file the code falls back to stdin, so this only fires for an explicit bad path.","triggerScenarios":"Calling the apply subcommand with a `--patch-file <path>` where the path does not exist, is a directory, or the process lacks read permission — `std::fs::read_to_string` returns Err.","commonSituations":"Typo in the patch file path; relative path resolved against a different CWD than expected; file deleted by a temp cleaner or another agent between generation and apply; read-only mount or sandbox denying access.","solutions":["Verify the path exists and is readable: `ls -l <path>` before running apply","Use an absolute path, or run from the directory where the patch file lives","Regenerate the patch file if it was cleaned up or truncated","Check permissions (`chmod u+r`) and that the file is not a directory"],"exampleFix":"// before\nlet patch = std::fs::read_to_string(&path)\n    .map_err(|e| anyhow::anyhow!(\"Failed to read patch {}: {}\", path.display(), e))?;\n// after\nif !path.is_file() { bail!(\"Patch file {} does not exist\", path.display()); }\nlet patch = std::fs::read_to_string(&path)\n    .map_err(|e| anyhow::anyhow!(\"Failed to read patch {}: {}\", path.display(), e))?;","handlingStrategy":"validation","validationCode":"// Rust\nif !path.is_file() {\n    bail!(\"patch file {} does not exist or is not a file\", path.display());\n}\nlet patch = std::fs::read_to_string(&path)?;","typeGuard":null,"tryCatchPattern":"// Rust\nmatch std::fs::read_to_string(&path) {\n    Ok(p) => p,\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => {\n        bail!(\"patch file {} not found; check the path and CWD\", path.display());\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Use absolute paths for patch files","Confirm the file exists right after generating it, before applying","Avoid leaving patch files in tmpwatch-cleaned directories","Check file readability under the sandbox/user that runs apply"],"tags":["filesystem","io","patch"],"backgroundTag":"file-read-failed","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"}