{"record":{"id":"57279e1edc060388","repo":"Hmbown/CodeWhale","slug":"path-has-no-parent-directory","errorCode":null,"errorMessage":"path has no parent directory: {}","messagePattern":"path has no parent directory: (.+?)","errorType":"validation","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/utils.rs","lineNumber":388,"sourceCode":"    const MAX_PERSIST_ATTEMPTS: usize = 6;\n    // 5 ERROR_ACCESS_DENIED, 32 ERROR_SHARING_VIOLATION, 33 ERROR_LOCK_VIOLATION.\n    let transient = error.kind() == std::io::ErrorKind::PermissionDenied\n        || matches!(error.raw_os_error(), Some(5 | 32 | 33));\n    if !transient || attempt + 1 >= MAX_PERSIST_ATTEMPTS {\n        return None;\n    }\n    Some(std::time::Duration::from_millis(\n        10u64.saturating_mul(1u64 << attempt),\n    ))\n}\n\nfn write_atomic_with_permissions(\n    path: &Path,\n    contents: &[u8],\n    #[cfg_attr(not(unix), allow(unused_variables))] permission_policy: AtomicWritePermissions,\n) -> std::io::Result<()> {\n    let parent = path.parent().ok_or_else(|| {\n        std::io::Error::new(\n            std::io::ErrorKind::InvalidInput,\n            format!(\"path has no parent directory: {}\", path.display()),\n        )\n    })?;\n\n    // Capture ordinary rwx bits before replacement. Use symlink_metadata so we\n    // do not follow links: an inaccessible or dangling symlink target must not\n    // abort the write — rename still replaces the directory entry, matching\n    // the pre-#4606 private write_atomic behavior. Symlink entries themselves\n    // are treated as \"no mode to preserve\" (new ordinary file after rename);\n    // only regular-file modes are restored. Mask with 0o777 so setuid/setgid/\n    // sticky are never restored after rewriting content.\n    #[cfg(unix)]\n    let existing_workspace_mode = if permission_policy == AtomicWritePermissions::Workspace {\n        match fs::symlink_metadata(path) {\n            Ok(metadata) if metadata.file_type().is_symlink() => None,\n            Ok(metadata) => {\n                use std::os::unix::fs::PermissionsExt;","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/utils.rs#L370-L406","documentation":"write_atomic_with_permissions needs the parent directory to stage its temporary file before renaming; it calls path.parent() and errors with ErrorKind::InvalidInput when the path has no parent component. Only paths with no directory part at all hit this (parent() returns None), e.g. a bare file name is usually fine (parent = \"\"), so this is a genuinely degenerate input guard.","triggerScenarios":"Calling write_atomic or write_atomic_workspace with a Path that has no parent component per std::path::Path::parent() — e.g. a root-relative oddity or a path constructed without any directory component in a context where parent() is None.","commonSituations":"Programmatically built PathBuf from an empty or malformed string, passing a bare component where an absolute path was expected, path munging that stripped the directory.","solutions":["Pass an absolute or directory-qualified path (e.g. workspace.join(file_name)).","Canonicalize/validate the path before writing.","Reject empty or component-less paths at the API boundary."],"exampleFix":"// before\nwrite_atomic(Path::new(\"config.toml\"), &bytes)?;\n// after\nwrite_atomic(&workspace_root.join(\"config.toml\"), &bytes)?;","handlingStrategy":"validation","validationCode":"debug_assert!(path.parent().is_some(), \"write path must have a parent: {}\", path.display());","typeGuard":null,"tryCatchPattern":"if path.parent().is_none() {\n    return Err(anyhow!(\"cannot atomically write path without parent: {}\", path.display()));\n}","preventionTips":["Always build write targets as directory.join(file_name).","Canonicalize user-supplied paths before writing.","Reject empty or bare-component paths at the config layer."],"tags":["filesystem","io","path"],"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"}