sxyazi/yazi · critical

Failed to get config directory

Error message

Failed to get config directory

What it means

Windows branch of Xdg::load_config_dir: panics via expect when YAZI_CONFIG_HOME is not set to an absolute path and dirs::config_dir() (the Roaming AppData root, %APPDATA%) returns None, so there is no base to join "yazi\config" onto. Evaluated once per process through a OnceLock at startup (Xdg::load).

Source

Thrown at yazi-fs/src/xdg.rs:30

		Self::runtime_dir();
		Self::temp_dir();
	}

	pub fn config_dir() -> &'static PathBuf {
		static ONCE: OnceLock<PathBuf> = OnceLock::new();
		ONCE.get_or_init(Self::load_config_dir)
	}

	fn load_config_dir() -> PathBuf {
		if let Some(p) = env::var_os("YAZI_CONFIG_HOME").map(PathBuf::from)
			&& p.is_absolute()
		{
			return p;
		}

		#[cfg(windows)]
		{
			dirs::config_dir().map(|p| p.join("yazi\\config")).expect("Failed to get config directory")
		}
		#[cfg(unix)]
		{
			env::var_os("XDG_CONFIG_HOME")
				.map(PathBuf::from)
				.filter(|p| p.is_absolute())
				.map(|p| p.join("yazi"))
				.or_else(|| dirs::home_dir().map(|h| h.join(".config/yazi")))
				.expect("Failed to get config directory")
		}
	}

	pub fn cache_dir() -> &'static PathBuf {
		static ONCE: OnceLock<PathBuf> = OnceLock::new();
		ONCE.get_or_init(Self::load_cache_dir)
	}

	fn load_cache_dir() -> PathBuf {

View on GitHub (pinned to 94abcfa92f)

Solutions

  1. Set YAZI_CONFIG_HOME to an absolute path — it short-circuits the whole Windows lookup
  2. Restore a valid APPDATA for the account, or run under a normal interactive user profile instead of SYSTEM
  3. For services and scheduled tasks, wrap the launch in a script that sets APPDATA or YAZI_CONFIG_HOME first
  4. Verify with `echo %APPDATA%` in the exact context that starts yazi

Example fix

REM before: APPDATA unset -> panic "Failed to get config directory"
set YAZI_CONFIG_HOME=C:\Users\me\.config\yazi
yazi.exe
Defensive patterns

Strategy: validation

Validate before calling

#[cfg(windows)]
fn config_dir_ok() -> bool {
    std::env::var_os("YAZI_CONFIG_HOME").is_some_and(|v| std::path::Path::new(&v).is_absolute())
        || std::env::var_os("APPDATA").is_some_and(|v| std::path::Path::new(&v).is_absolute())
}

Prevention

When it happens

Trigger: First call to Xdg::config_dir() on Windows with APPDATA unset, empty, or stripped — typical for SYSTEM/service accounts without a roaming profile, hardened CI runners, or wrappers that sanitize the environment.

Common situations: Running yazi/ya as a Windows service or scheduled task under SYSTEM; CI containers on Windows with a mutilated environment; APPDATA removed by an env-cleaning launcher.

Related errors


AI-assisted analysis of sxyazi/yazi@94abcfa92f (2026-08-16). Data as JSON: /api/errors/34dbf6e81db14aa0. Report an issue: GitHub.