{"record":{"id":"edd9affd70595bb4","repo":"Hmbown/CodeWhale","slug":"failed-to-create-owned-skill-directory","errorCode":null,"errorMessage":"failed to create owned skill directory {}","messagePattern":"failed to create owned skill directory (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/skills/mutation.rs","lineNumber":234,"sourceCode":"        bail!(\n            \"owned skill root {} escapes anchor {}\",\n            skills_dir.display(),\n            anchor.display()\n        );\n    }\n    Ok(())\n}\n\nfn create_owned_directory(path: &Path) -> Result<()> {\n    match fs::create_dir(path) {\n        Ok(()) => {}\n        Err(err) if err.kind() == ErrorKind::AlreadyExists => {}\n        Err(err) => {\n            return Err(err).with_context(|| format!(\"failed to create {}\", path.display()));\n        }\n    }\n    if !checked_real_directory(path)? {\n        bail!(\"failed to create owned skill directory {}\", path.display());\n    }\n    Ok(())\n}\n\nfn prepare_owned_target(\n    workspace: &Path,\n    home: Option<&Path>,\n    target: SkillTargetScope,\n) -> Result<PathBuf> {\n    let skills_dir = resolve_owned_target(workspace, home, target)?;\n    let anchor = owned_anchor(workspace, home, target)?;\n    if !checked_real_directory(anchor)? {\n        bail!(\"owned skill anchor {} does not exist\", anchor.display());\n    }\n\n    let codewhale_dir = anchor.join(\".codewhale\");\n    if !checked_real_directory(&codewhale_dir)? {\n        create_owned_directory(&codewhale_dir)?;","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/src/skills/mutation.rs#L216-L252","documentation":"`create_owned_directory` calls `fs::create_dir` (ignoring AlreadyExists) and then re-verifies with `checked_real_directory`, which rejects anything that is not a real, non-symlinked directory. This bail fires when creation 'succeeded' (or the path already existed) but the resulting path is not a real directory — meaning a file, symlink, or race occupies the path.","triggerScenarios":"`prepare_owned_target` calls `create_owned_directory` on `<anchor>/.codewhale` or `<anchor>/.codewhale/skills` while a regular file or symlink already exists at that exact path (create_dir fails with AlreadyExists, which is swallowed, then the directory check fails); a concurrent process creates a symlink at the path between create and check; permissions cause a partial/failing state surfaced by the metadata check.","commonSituations":"A stale file named `.codewhale` or `skills` left by an earlier broken tool; a dotfile manager that planted symlinks at these paths; two agents racing to initialize the same workspace where one creates a symlink; an adversarial or accidental file at the path that the security check refuses to traverse.","solutions":["Inspect the path: if it is a file or symlink, remove it (`rm <path>`) and re-run the operation so a real directory is created","Re-run the install/import after clearing the impostor path; `create_dir` will then succeed for real","Check for concurrent Codewhale sessions or scripts touching the workspace and serialize initialization","Verify permissions on the anchor so directory creation can actually complete"],"exampleFix":"// before: skills path is a symlink, so creation is a no-op and check fails\n$ ls -la ~/.codewhale/skills\nskills -> /mnt/data/skills\n// after: remove the impostor and recreate as a real directory\n$ rm ~/.codewhale/skills\n$ mkdir ~/.codewhale/skills","handlingStrategy":"validation","validationCode":"fn creatable_dir(p: &Path) -> Result<(), String> {\n    match std::fs::symlink_metadata(p) {\n        Ok(m) if m.is_dir() => Ok(()),\n        Ok(_) => Err(format!(\"{} exists and is not a directory; remove it first\", p.display())),\n        Err(_) => Ok(()), // does not exist; create_dir can make it\n    }\n}","typeGuard":"fn is_dir_or_absent(p: &Path) -> bool {\n    !std::fs::symlink_metadata(p).map(|m| !m.is_dir()).unwrap_or(false)\n}","tryCatchPattern":"match install_remote(workspace, home, scope) {\n    Err(e) if e.to_string().contains(\"failed to create owned skill directory\") => {\n        eprintln!(\"{} — remove the file/symlink at that path and retry\", e);\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Ensure nothing (file or symlink) already occupies .codewhale or .codewhale/skills before initializing","Do not run multiple Codewhale sessions racing to create the same owned chain","Investigate any stale files left by crashed tools at these paths","Keep antivirus/sync tools from substituting symlinks into the workspace mid-run"],"tags":["filesystem","mkdir","symlink","race-condition"],"backgroundTag":"mkdir-permission-denied","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"}