{"record":{"id":"66ef682f6cc39cb6","repo":"sxyazi/yazi","slug":"failed-to-get-cache-directory","errorCode":null,"errorMessage":"Failed to get cache directory","messagePattern":"Failed to get cache directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"yazi-fs/src/xdg.rs","lineNumber":51,"sourceCode":"\t\t{\n\t\t\tenv::var_os(\"XDG_CONFIG_HOME\")\n\t\t\t\t.map(PathBuf::from)\n\t\t\t\t.filter(|p| p.is_absolute())\n\t\t\t\t.map(|p| p.join(\"yazi\"))\n\t\t\t\t.or_else(|| dirs::home_dir().map(|h| h.join(\".config/yazi\")))\n\t\t\t\t.expect(\"Failed to get config directory\")\n\t\t}\n\t}\n\n\tpub fn cache_dir() -> &'static PathBuf {\n\t\tstatic ONCE: OnceLock<PathBuf> = OnceLock::new();\n\t\tONCE.get_or_init(Self::load_cache_dir)\n\t}\n\n\tfn load_cache_dir() -> PathBuf {\n\t\t#[cfg(windows)]\n\t\t{\n\t\t\tdirs::cache_dir().map(|p| p.join(\"yazi\")).expect(\"Failed to get cache directory\")\n\t\t}\n\t\t#[cfg(unix)]\n\t\t{\n\t\t\tenv::var_os(\"XDG_CACHE_HOME\")\n\t\t\t\t.map(PathBuf::from)\n\t\t\t\t.filter(|p| p.is_absolute())\n\t\t\t\t.map(|p| p.join(\"yazi\"))\n\t\t\t\t.or_else(|| dirs::home_dir().map(|h| h.join(\".cache/yazi\")))\n\t\t\t\t.expect(\"Failed to get cache directory\")\n\t\t}\n\t}\n\n\tpub fn state_dir() -> &'static PathBuf {\n\t\tstatic ONCE: OnceLock<PathBuf> = OnceLock::new();\n\t\tONCE.get_or_init(Self::load_state_dir)\n\t}\n\n\tfn load_state_dir() -> PathBuf {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/sxyazi/yazi/blob/5f901b886b14de1f17460b6e52e9de5d67f8aba9/yazi-fs/src/xdg.rs#L33-L69","documentation":"Yazi's XDG helper caches the cache directory on first use via OnceLock; on Windows it calls dirs::cache_dir() and panics via expect() if the OS returns None. dirs::cache_dir() returns None when it cannot resolve the user profile (missing USERPROFILE/APPDATA environment variables). This is a hard panic, not a recoverable Result, because yazi cannot run without a cache location.","triggerScenarios":"Calling yazi_fs::xdg cache_dir accessor on Windows when dirs::cache_dir() returns None, i.e. the %USERPROFILE% or %APPDATA% env vars are unset or invalid at process startup.","commonSituations":"Running `ya`/`yazi` from a stripped environment (services, SSH with env clearing, runas accounts, CI containers on Windows) where the user profile env vars are missing; corrupted user registry profile paths.","solutions":["Ensure USERPROFILE and APPDATA (or HOME) environment variables are set to an absolute path before launching yazi","If launched from a service/SSH, run under an interactive user session or export the vars manually in the wrapper script","Check the Windows user profile exists and the registry ProfileImagePath points to a valid directory"],"exampleFix":"// before (broken launch wrapper)\nstart yazi.exe\n// after\nset \"USERPROFILE=%SystemDrive%\\Users\\alice\"\nset \"APPDATA=%USERPROFILE%\\AppData\\Roaming\"\nyazi.exe","handlingStrategy":"validation","validationCode":"if !process::Command::new(\"cmd\").args([\"/C\",\"echo %APPDATA%\"]).status().is_ok() || env::var_os(\"APPDATA\").is_none() { eprintln!(\"APPDATA/USERPROFILE missing; yazi cache dir unavailable\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Launch yazi from a shell with the full user environment","Never strip USERPROFILE/APPDATA in wrappers or services","Pre-check env vars in launch scripts on Windows"],"tags":["windows","xdg","cache-dir","panic","env"],"backgroundTag":"missing-user-profile-env-var","analyzedSha":"5f901b886b14de1f17460b6e52e9de5d67f8aba9","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}