{"record":{"id":"0972a585f2c9331c","repo":"Hmbown/CodeWhale","slug":"path-has-no-parent","errorCode":null,"errorMessage":"path has no parent","messagePattern":"path has no parent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/integrations/dsh/receipt.rs","lineNumber":160,"sourceCode":"        }\n    }\n\n    pub(crate) fn save(&self, path: &Path) -> Result<()> {\n        let parent = path\n            .parent()\n            .ok_or_else(|| anyhow::anyhow!(\"receipt path has no parent\"))?;\n        std::fs::create_dir_all(parent).with_context(|| format!(\"create {}\", parent.display()))?;\n        let json = serde_json::to_vec_pretty(self)?;\n        write_atomic(path, &json)\n    }\n}\n\n/// Write via a sibling temp file + rename so a crash never leaves a torn\n/// receipt or overlay behind.\npub(crate) fn write_atomic(path: &Path, bytes: &[u8]) -> Result<()> {\n    let parent = path\n        .parent()\n        .ok_or_else(|| anyhow::anyhow!(\"path has no parent\"))?;\n    let tmp = parent.join(format!(\n        \".{}.tmp-{}\",\n        path.file_name()\n            .map(|n| n.to_string_lossy().into_owned())\n            .unwrap_or_else(|| \"file\".to_string()),\n        std::process::id()\n    ));\n    std::fs::write(&tmp, bytes).with_context(|| format!(\"write {}\", tmp.display()))?;\n    #[cfg(unix)]\n    {\n        use std::os::unix::fs::PermissionsExt;\n        let _ = std::fs::set_permissions(&tmp, std::fs::Permissions::from_mode(0o600));\n    }\n    std::fs::rename(&tmp, path).with_context(|| format!(\"rename into {}\", path.display()))?;\n    Ok(())\n}\n\npub(crate) fn now_rfc3339() -> String {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/integrations/dsh/receipt.rs#L142-L178","documentation":"`write_atomic` writes via a sibling temp file plus rename so a crash never leaves a torn receipt. It needs `path.parent()` to place the temp file next to the target; if `parent()` returns `None` (empty path or filesystem root) it throws this error instead of guessing a location.","triggerScenarios":"`write_atomic(path, bytes)` reached with a parentless path — reachable directly, but typically via `Receipt::save` after the same guard already ran there.","commonSituations":"Same as 1790: empty or root paths, dropped directory components when assembling paths from config or CLI arguments.","solutions":["Ensure the target path has a directory component; join the file name onto a real directory.","Reject empty/root paths at the configuration boundary before any write is attempted.","If you call `write_atomic` directly, validate `path.parent().is_some()` first."],"exampleFix":"// before\nwrite_atomic(Path::new(\"/\"), &json)?;\n// after\nlet path = dir.join(\"receipt.json\");\nassert!(path.parent().is_some());\nwrite_atomic(&path, &json)?;","handlingStrategy":"validation","validationCode":"if path.parent().map(|p| p.as_os_str().is_empty()).unwrap_or(true) {\n    return Err(anyhow!(\"atomic write target must have a parent directory\"));\n}","typeGuard":"fn writable_target(path: &Path) -> bool {\n    path.file_name().is_some() && path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)\n}","tryCatchPattern":"if let Err(e) = write_atomic(&path, &bytes) {\n    if e.to_string().contains(\"no parent\") { eprintln!(\"bad path: {e}\"); }\n}","preventionTips":["Call `write_atomic` only via `Receipt::save` with fully-qualified paths.","Canonicalize the directory component before joining the file name.","Add a startup assertion that all configured write paths are absolute."],"tags":["filesystem","path","io"],"backgroundTag":"file-write-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"}