sxyazi/yazi · error

Failed to get asset directory

Error message

Failed to get asset directory

What it means

On Windows, load_asset_dir derives the asset cache dir from dirs::cache_dir() and panics with 'Failed to get asset directory' when the platform cannot supply a cache directory (no known cache location for the user profile).

Solutions

  1. Ensure LOCALAPPDATA (and USERPROFILE) environment variables are set correctly
  2. Run in an interactive session with a real user profile instead of a service context
  3. Recreate/repair the Windows user profile
Defensive patterns

Strategy: fallback

Validate before calling

import os
def asset_dir_ok():
    base = os.environ.get("LOCALAPPDATA") or os.environ.get("USERPROFILE")
    return bool(base and os.path.isdir(base))

Try / catch

// recover from the panic at process boundary, or set env before launching
if (!process.env.LOCALAPPDATA) {
  throw new Error("Set LOCALAPPDATA before starting yazi on Windows");
}

Prevention

When it happens

Trigger: dirs::cache_dir() returns None — typically a broken or unset USERPROFILE/LOCALAPPDATA environment on Windows.

Common situations: Running in stripped service/sandbox environments where LOCALAPPDATA is missing; corrupted user profiles; non-interactive sessions.

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 sxyazi/yazi@a541adde4e (2026-09-18). Data as JSON: /api/errors/f06faee95af195e8. Report an issue: GitHub.

Appendix: source

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

		{
			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 asset_dir() -> &'static PathBuf {
		static DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_asset_dir);
		&DIR
	}

	fn load_asset_dir() -> PathBuf {
		#[cfg(windows)]
		{
			dirs::cache_dir().map(|p| p.join("yazi")).expect("Failed to get asset directory")
		}
		#[cfg(unix)]
		{
			env::var_os("XDG_CACHE_HOME")
				.map(PathBuf::from)
				.filter(|p| p.is_absolute())
				.map(|p| p.join("yazi"))
				.or_else(|| dirs::home_dir().map(|h| h.join(".cache/yazi")))
				.expect("Failed to get asset directory")
		}
	}

	pub fn state_dir() -> &'static PathBuf {
		static DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_state_dir);
		&DIR
	}

	fn load_state_dir() -> PathBuf {

View on GitHub (pinned to a541adde4e)