Hmbown/CodeWhale · error
path has no parent
Error message
path has no parent
What it means
`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.
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.
Example fix
// before
write_atomic(Path::new("/"), &json)?;
// after
let path = dir.join("receipt.json");
assert!(path.parent().is_some());
write_atomic(&path, &json)?; Defensive patterns
Strategy: validation
Validate before calling
if path.parent().map(|p| p.as_os_str().is_empty()).unwrap_or(true) {
return Err(anyhow!("atomic write target must have a parent directory"));
} Type guard
fn writable_target(path: &Path) -> bool {
path.file_name().is_some() && path.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)
} Try / catch
if let Err(e) = write_atomic(&path, &bytes) {
if e.to_string().contains("no parent") { eprintln!("bad path: {e}"); }
} Prevention
- 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.
When it happens
Trigger: `write_atomic(path, bytes)` reached with a parentless path — reachable directly, but typically via `Receipt::save` after the same guard already ran there.
Common situations: Same as 1790: empty or root paths, dropped directory components when assembling paths from config or CLI arguments.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- path has no parent directory
- receipt path has no parent
- 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/0972a585f2c9331c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tui/src/integrations/dsh/receipt.rs:160
}
}
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()
));
std::fs::write(&tmp, bytes).with_context(|| format!("write {}", tmp.display()))?;
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let _ = std::fs::set_permissions(&tmp, std::fs::Permissions::from_mode(0o600));
}
std::fs::rename(&tmp, path).with_context(|| format!("rename into {}", path.display()))?;
Ok(())
}
pub(crate) fn now_rfc3339() -> String {View on GitHub (pinned to 73e0f67d83)