zed-industries/zed · error

failed to determine XDG_STATE_HOME directory

Error message

failed to determine XDG_STATE_HOME directory

What it means

Panic when the state directory base cannot be determined on Linux/BSD: FLATPAK_XDG_STATE_HOME/XDG_STATE_HOME is not usable and no home directory exists (HOME unset), so the ~/.local/state/zed path (used for runtime state) cannot be formed. Note state_dir has its own OnceLock, so a panic here poisons only state-dir consumers.

Source

Thrown at crates/paths/src/paths.rs:180

                .join(APP_NAME)
        } else {
            config_dir().clone() // Fallback
        }
    })
}

pub fn state_dir() -> &'static PathBuf {
    static STATE_DIR: OnceLock<PathBuf> = OnceLock::new();
    STATE_DIR.get_or_init(|| {
        if cfg!(target_os = "macos") {
            return home_dir().join(".local").join("state").join(APP_NAME);
        }

        if cfg!(any(target_os = "linux", target_os = "freebsd")) {
            return if let Ok(flatpak_xdg_state) = std::env::var("FLATPAK_XDG_STATE_HOME") {
                flatpak_xdg_state.into()
            } else {
                dirs::state_dir().expect("failed to determine XDG_STATE_HOME directory")
            }
            .join(APP_NAME_LOWERCASE);
        } else {
            // Windows
            return dirs::data_local_dir()
                .expect("failed to determine LocalAppData directory")
                .join(APP_NAME);
        }
    })
}

/// Returns the path to the temp directory used by Zed.
pub fn temp_dir() -> &'static PathBuf {
    static TEMP_DIR: OnceLock<PathBuf> = OnceLock::new();
    TEMP_DIR.get_or_init(|| {
        if cfg!(target_os = "macos") {
            return dirs::cache_dir()
                .expect("failed to determine cachesDirectory directory")

View on GitHub (pinned to f4178619ac)

Solutions

  1. Set HOME or an absolute XDG_STATE_HOME in the environment
  2. Under Flatpak, ensure FLATPAK_XDG_STATE_HOME is exported to the sandbox
  3. Return an error (or fall back to config_dir as the comment suggests) instead of unwrapping
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/paths/src/paths.rs:180 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/e81074c1de15c5f4. Report an issue: GitHub.