Hmbown/CodeWhale · error

failed to create owned skill directory

Error message

failed to create owned skill directory {}

What it means

`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.

Solutions

  1. 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
  2. Re-run the install/import after clearing the impostor path; `create_dir` will then succeed for real
  3. Check for concurrent Codewhale sessions or scripts touching the workspace and serialize initialization
  4. Verify permissions on the anchor so directory creation can actually complete

Example fix

// before: skills path is a symlink, so creation is a no-op and check fails
$ ls -la ~/.codewhale/skills
skills -> /mnt/data/skills
// after: remove the impostor and recreate as a real directory
$ rm ~/.codewhale/skills
$ mkdir ~/.codewhale/skills
Defensive patterns

Strategy: validation

Validate before calling

fn creatable_dir(p: &Path) -> Result<(), String> {
    match std::fs::symlink_metadata(p) {
        Ok(m) if m.is_dir() => Ok(()),
        Ok(_) => Err(format!("{} exists and is not a directory; remove it first", p.display())),
        Err(_) => Ok(()), // does not exist; create_dir can make it
    }
}

Type guard

fn is_dir_or_absent(p: &Path) -> bool {
    !std::fs::symlink_metadata(p).map(|m| !m.is_dir()).unwrap_or(false)
}

Try / catch

match install_remote(workspace, home, scope) {
    Err(e) if e.to_string().contains("failed to create owned skill directory") => {
        eprintln!("{} — remove the file/symlink at that path and retry", e);
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/edd9affd70595bb4. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/skills/mutation.rs:234

        bail!(
            "owned skill root {} escapes anchor {}",
            skills_dir.display(),
            anchor.display()
        );
    }
    Ok(())
}

fn create_owned_directory(path: &Path) -> Result<()> {
    match fs::create_dir(path) {
        Ok(()) => {}
        Err(err) if err.kind() == ErrorKind::AlreadyExists => {}
        Err(err) => {
            return Err(err).with_context(|| format!("failed to create {}", path.display()));
        }
    }
    if !checked_real_directory(path)? {
        bail!("failed to create owned skill directory {}", path.display());
    }
    Ok(())
}

fn prepare_owned_target(
    workspace: &Path,
    home: Option<&Path>,
    target: SkillTargetScope,
) -> Result<PathBuf> {
    let skills_dir = resolve_owned_target(workspace, home, target)?;
    let anchor = owned_anchor(workspace, home, target)?;
    if !checked_real_directory(anchor)? {
        bail!("owned skill anchor {} does not exist", anchor.display());
    }

    let codewhale_dir = anchor.join(".codewhale");
    if !checked_real_directory(&codewhale_dir)? {
        create_owned_directory(&codewhale_dir)?;

View on GitHub (pinned to 73e0f67d83)