tw93/Pake · error · std::io::Error

Can't create dir

Error message

Can't create dir {}: {err}

What it means

get_data_dir joins the package name onto the config dir and creates the directory if missing; create_dir_all failures are rewrapped with this message including the target path. This usually reflects filesystem permission or path problems rather than app logic.

Solutions

  1. Inspect the path in the message and fix permissions on the parent config directory (chmod/chown).
  2. Remove or rename a non-directory file occupying the target path.
  3. Free disk space or remount the volume read-write, then relaunch.

Example fix

// before
$ ls ~/.config/pake
// after
$ mv ~/.config/pake ~/.config/pake.bak  # if it is a file, then relaunch the app
Defensive patterns

Strategy: try-catch

Validate before calling

const dir = path.join(os.homedir(), '.config', pkgName);
if (fs.existsSync(dir) && !fs.statSync(dir).isDirectory()) throw new Error(`${dir} exists and is not a directory`);
fs.mkdirSync(dir, { recursive: true });

Try / catch

match std::fs::create_dir_all(&data_dir) { Err(err) => { eprintln!("check permissions/occupants of {}: {err}", data_dir.display()); return Err(...); }, Ok(_) => {} }

Prevention

When it happens

Trigger: std::fs::create_dir_all(&data_dir) returns Err because a parent is not writable, the path exists as a file, the disk is full, or policy (sandbox/permission) blocks creation.

Common situations: Read-only HOME or config filesystem; a file named like the app dir already exists at ~/.config/<package_name>; enterprise-managed machines restricting ~/.config writes.

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 tw93/Pake@c8fe8a3f1a (2026-09-20). Data as JSON: /api/errors/b36e9e4345fda45c. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/util.rs:41

    (pake_config, tauri_config)
}

pub fn get_data_dir(app: &AppHandle, package_name: String) -> std::io::Result<PathBuf> {
    let data_dir = app
        .path()
        .config_dir()
        .map_err(|err| {
            std::io::Error::new(
                std::io::ErrorKind::NotFound,
                format!("Failed to resolve config dir: {err}"),
            )
        })?
        .join(package_name);

    if !data_dir.exists() {
        std::fs::create_dir_all(&data_dir).map_err(|err| {
            std::io::Error::new(
                err.kind(),
                format!("Can't create dir {}: {err}", data_dir.display()),
            )
        })?;
    }

    Ok(data_dir)
}

pub fn read_last_url(path: &Path) -> std::io::Result<Option<tauri::Url>> {
    match std::fs::read_to_string(path) {
        Ok(value) => Ok(tauri::Url::parse(&value)
            .ok()
            .filter(|url| matches!(url.scheme(), "http" | "https"))),
        Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(None),
        Err(error) => Err(error),
    }
}

View on GitHub (pinned to c8fe8a3f1a)