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

Failed to resolve config dir

Error message

Failed to resolve config dir: {err}

What it means

get_data_dir resolves the platform config directory via Tauri's path API; if resolution fails (rare, e.g. no valid base directories on the system) it wraps the tauri::Error into a NotFound io::Error with this message. build_window surfaces it as the app's window-build failure.

Solutions

  1. Launch the app inside a normal desktop session with HOME and XDG_CONFIG_HOME set.
  2. Set XDG_CONFIG_HOME explicitly to a writable directory before launching.
  3. Check the source error in the message for the platform-specific cause and fix that environment issue.
Defensive patterns

Strategy: fallback

Validate before calling

if (!process.env.HOME && !process.env.XDG_CONFIG_HOME && process.platform === 'linux') throw new Error('no config dir base: set XDG_CONFIG_HOME');

Try / catch

match get_data_dir(app, package_name) { Err(e) => { eprintln!("cannot resolve config dir, launch in a desktop session or set XDG_CONFIG_HOME: {e}"); return Err(e.into()); }, Ok(d) => d }

Prevention

When it happens

Trigger: app.path().config_dir() returns Err, typically on Linux when XDG base-directory resolution fails or the runtime environment lacks required variables/homedir context.

Common situations: Running the binary in a stripped container or systemd service without XDG_CONFIG_HOME and no user record; corrupted environment in CI sandboxes.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of tw93/Pake@c8fe8a3f1a (2026-09-20). Data as JSON: /api/errors/e6565722d36fdbec. Report an issue: GitHub.

Appendix: source

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

        serde_json::from_str(include_str!("../pake.json")).expect("Failed to parse pake config");

    #[cfg(feature = "cli-build")]
    let tauri_config: Config = serde_json::from_str(include_str!("../.pake/tauri.conf.json"))
        .expect("Failed to parse tauri config");

    #[cfg(not(feature = "cli-build"))]
    let tauri_config: Config = serde_json::from_str(include_str!("../tauri.conf.json"))
        .expect("Failed to parse tauri config");

    (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)
}

View on GitHub (pinned to c8fe8a3f1a)