sxyazi/yazi · critical
Failed to get cache directory
Error message
Failed to get cache directory
What it means
Windows branch of Xdg::load_cache_dir: panics via expect when dirs::cache_dir() — the LocalAppData root (%LOCALAPPDATA%) — returns None, so "yazi" cannot be joined onto it. Cached previews, plugin state, and stamps all live under this directory; it is resolved once per process at startup.
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 cache_dir() -> &'static PathBuf {
static ONCE: OnceLock<PathBuf> = OnceLock::new();
ONCE.get_or_init(Self::load_cache_dir)
}
fn load_cache_dir() -> PathBuf {
#[cfg(windows)]
{
dirs::cache_dir().map(|p| p.join("yazi")).expect("Failed to get cache 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 cache directory")
}
}
pub fn state_dir() -> &'static PathBuf {
static ONCE: OnceLock<PathBuf> = OnceLock::new();
ONCE.get_or_init(Self::load_state_dir)
}
fn load_state_dir() -> PathBuf {View on GitHub (pinned to 94abcfa92f)
Solutions
- Restore LOCALAPPDATA to a valid absolute path for the account that runs yazi
- Run under a normal interactive user profile instead of SYSTEM/service accounts
- Wrap service launches in a script that sets LOCALAPPDATA explicitly
- Verify with `echo %LOCALAPPDATA%` in the same context that launches the binary
Example fix
REM before: LOCALAPPDATA unset -> panic "Failed to get cache directory" set LOCALAPPDATA=C:\Users\me\AppData\Local yazi.exe
Defensive patterns
Strategy: validation
Validate before calling
#[cfg(windows)]
fn cache_dir_ok() -> bool {
std::env::var_os("LOCALAPPDATA").is_some_and(|v| std::path::Path::new(&v).is_absolute())
} Prevention
- Set LOCALAPPDATA explicitly in service wrappers and CI on Windows
- Run under an interactive user profile rather than SYSTEM
- Verify `echo %LOCALAPPDATA%` in the launching context
When it happens
Trigger: First call to Xdg::cache_dir() on Windows with LOCALAPPDATA unset or unresolvable: service/SYSTEM contexts, stripped CI environments, or profiles where the local app-data root is disabled.
Common situations: Scheduled tasks and services running without a user profile; Windows CI runners that clear LOCALAPPDATA; portable/locked-down machines with redirected profiles.
Related errors
- Failed to get config directory
- Failed to get state directory
- failed to get current working directory
- Time went backwards
- failed to spawn chafa: {e}
AI-assisted analysis of sxyazi/yazi@94abcfa92f (2026-08-16).
Data as JSON: /api/errors/66ef682f6cc39cb6.
Report an issue: GitHub.