Hmbown/CodeWhale · error
receipt path has no parent
Error message
receipt path has no parent
What it means
`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.
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.
Example fix
// before
receipt.save(Path::new("receipt.json"))?;
// after
let path = Path::new("/var/lib/codewhale").join("receipt.json");
receipt.save(&path)?; Defensive patterns
Strategy: validation
Validate before calling
let path = Path::new(target);
if path.parent().map(|p| p.as_os_str().is_empty()).unwrap_or(true) {
return Err(anyhow!("receipt path must include a parent directory"));
} Type guard
fn has_parent(path: &Path) -> bool {
path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)
} Try / catch
match receipt.save(&path) {
Err(e) if e.to_string().contains("no parent") => eprintln!("provide a full path with a directory: {e}"),
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- path has no parent
- path has no parent directory
- Codewhale credentials directory cannot be a volume root
- Codewhale-owned xAI OAuth path has the wrong filesystem type
- continual harness state has no parent
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/98abffa1fbbeb841.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/integrations/dsh/receipt.rs:148
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(Self::default()),
Err(error) => {
Err(error).with_context(|| format!("read DSH receipt {}", path.display()))
}
}
}
pub(crate) fn push(&mut self, entry: DshReceiptEntry) {
self.history.push(entry);
if self.history.len() > MAX_HISTORY {
let excess = self.history.len() - MAX_HISTORY;
self.history.drain(0..excess);
}
}
pub(crate) fn save(&self, path: &Path) -> Result<()> {
let parent = path
.parent()
.ok_or_else(|| anyhow::anyhow!("receipt path has no parent"))?;
std::fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
let json = serde_json::to_vec_pretty(self)?;
write_atomic(path, &json)
}
}
/// Write via a sibling temp file + rename so a crash never leaves a torn
/// receipt or overlay behind.
pub(crate) fn write_atomic(path: &Path, bytes: &[u8]) -> Result<()> {
let parent = path
.parent()
.ok_or_else(|| anyhow::anyhow!("path has no parent"))?;
let tmp = parent.join(format!(
".{}.tmp-{}",
path.file_name()
.map(|n| n.to_string_lossy().into_owned())
.unwrap_or_else(|| "file".to_string()),
std::process::id()View on GitHub (pinned to 73e0f67d83)