janhq/jan · critical

Failed to determine the home directory

Error message

Failed to determine the home directory

What it means

This is a panic (.expect) that occurs only when Tauri's path().data_dir() already failed AND the HOME (Unix) or USERPROFILE (Windows) environment variable is also unset. It is the inner fallback of app_data_dir_with_fallback — the last resort for locating the app data directory. In normal desktop use this is unreachable; it triggers in stripped-down headless/container environments.

Source

Thrown at src-tauri/src/core/app/commands.rs:91

                paths.push(legacy);
            }
        }
    }

    paths
}

fn app_data_dir_with_fallback<R: Runtime>(app_handle: &tauri::AppHandle<R>) -> PathBuf {
    let package_name = env!("CARGO_PKG_NAME");
    app_handle.path().data_dir().unwrap_or_else(|err| {
        log::error!("Failed to get data directory: {err}. Using home directory instead.");

        let home_dir = std::env::var(if cfg!(target_os = "windows") {
            "USERPROFILE"
        } else {
            "HOME"
        })
        .expect("Failed to determine the home directory");

        PathBuf::from(home_dir)
    })
    .join(package_name)
}

/// Resolve the Jan config file path without an AppHandle (for CLI use).
/// Canonical location is `%APPDATA%/Jan/settings.json` (or OS equivalent),
/// with fallback recovery from bundle-id location when needed.
pub fn resolve_config_file_path() -> PathBuf {
    let app_data = resolve_human_readable_app_data_dir().unwrap_or_else(|| {
        let package_name = env!("CARGO_PKG_NAME");
        let home = std::env::var("HOME")
            .or_else(|_| std::env::var("USERPROFILE"))
            .unwrap_or_default();
        PathBuf::from(home).join(package_name)
    });

View on GitHub (pinned to fad3f12a14)

Solutions

  1. Set the HOME environment variable (Unix) or USERPROFILE (Windows) before launching the app.
  2. Set XDG_DATA_HOME on Linux to explicitly specify the data directory.
  3. For systemd services, add `Environment=HOME=/var/lib/jan` to the unit file.
  4. For Docker, pass `-e HOME=/home/jan -v /home/jan:/home/jan`.

Example fix

# before (Docker)
docker run jan-app

# after
docker run -e HOME=/home/jan -e XDG_DATA_HOME=/home/jan/.local/share jan-app
Defensive patterns

Strategy: validation

Validate before calling

// Check env vars are set before relying on the fallback
fn ensure_home_available() -> Result<(), String> {
    let home = if cfg!(target_os = "windows") {
        std::env::var("USERPROFILE")
    } else {
        std::env::var("HOME")
    };
    home.map(|_| ()).map_err(|_| {
        "Neither HOME nor the Tauri data_dir is available. Set HOME or XDG_DATA_HOME.".to_string()
    })
}

Try / catch

// Replace .expect with a graceful error
let home_dir = std::env::var(if cfg!(target_os = "windows") { "USERPROFILE" } else { "HOME" });
let home = match home_dir {
    Ok(h) => PathBuf::from(h),
    Err(_) => {
        log::error!("HOME/USERPROFILE unset and data_dir failed; using /tmp as last resort");
        PathBuf::from("/tmp")
    }
};

Prevention

When it happens

Trigger: Running the Tauri app inside a container without HOME set and without XDG_DATA_HOME. Launching via a systemd unit or cron job that does not inherit the user environment. Running as a service account whose HOME is deliberately unset. macOS app bundle launched in a sandbox that strips env vars.

Common situations: Docker containers running the desktop app without -e HOME=/home/user. CI environments running integration tests against the GUI binary. systemd services missing Environment=HOME=. Root user with HOME unset.

Related errors


AI-assisted analysis of janhq/jan@fad3f12a14 (2026-08-12). Data as JSON: /api/errors/e0717d8fff16f1a7. Report an issue: GitHub.