{"record":{"id":"98abffa1fbbeb841","repo":"Hmbown/CodeWhale","slug":"receipt-path-has-no-parent","errorCode":null,"errorMessage":"receipt path has no parent","messagePattern":"receipt path has no parent","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/integrations/dsh/receipt.rs","lineNumber":148,"sourceCode":"            Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(Self::default()),\n            Err(error) => {\n                Err(error).with_context(|| format!(\"read DSH receipt {}\", path.display()))\n            }\n        }\n    }\n\n    pub(crate) fn push(&mut self, entry: DshReceiptEntry) {\n        self.history.push(entry);\n        if self.history.len() > MAX_HISTORY {\n            let excess = self.history.len() - MAX_HISTORY;\n            self.history.drain(0..excess);\n        }\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()","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/integrations/dsh/receipt.rs#L130-L166","documentation":"`Receipt::save` serializes the receipt to pretty JSON and writes it atomically. Before writing it calls `Path::parent()`, which returns `None` only for paths like a bare root (`/`) or an empty path, and this anyhow error signals that no parent directory can be derived. In practice the code cannot create a destination directory or place a temp file next to the receipt without a parent.","triggerScenarios":"Calling `receipt.save(path)` with a path that has no parent component: `Path::new(\"\")`, `Path::new(\"/\")`, or a constructed path that lost its directory prefix.","commonSituations":"Building the receipt path by joining only a file name onto nothing, mis-parsing config so the directory component is dropped, or passing the root directory itself as the save target.","solutions":["Pass a full path that includes a parent directory, e.g. `/var/lib/codewhale/receipt.json` instead of `receipt.json` or `/`.","Check where the path is constructed (config value or join chain) and confirm the directory component is not empty before calling `save`.","If a caller may legitimately pass a bare file name, resolve it against an explicit base directory first."],"exampleFix":"// before\nreceipt.save(Path::new(\"receipt.json\"))?;\n// after\nlet path = Path::new(\"/var/lib/codewhale\").join(\"receipt.json\");\nreceipt.save(&path)?;","handlingStrategy":"validation","validationCode":"let path = Path::new(target);\nif path.parent().map(|p| p.as_os_str().is_empty()).unwrap_or(true) {\n    return Err(anyhow!(\"receipt path must include a parent directory\"));\n}","typeGuard":"fn has_parent(path: &Path) -> bool {\n    path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)\n}","tryCatchPattern":"match receipt.save(&path) {\n    Err(e) if e.to_string().contains(\"no parent\") => eprintln!(\"provide a full path with a directory: {e}\"),\n    other => other?,\n}","preventionTips":["Always build receipt paths with a real directory joined to a file name.","Validate configured paths at startup that they contain a directory component.","Never pass `Path::new(\"\")` or `/` as a write target."],"tags":["filesystem","path","io"],"backgroundTag":"invalid-argument-value","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"}