{"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/94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2/yazi-fs/src/xdg.rs#L33-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"Scheduled tasks and services running without a user profile; Windows CI runners that clear LOCALAPPDATA; portable/locked-down machines with redirected profiles.","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"],"exampleFix":"REM before: LOCALAPPDATA unset -> panic \"Failed to get cache directory\"\nset LOCALAPPDATA=C:\\Users\\me\\AppData\\Local\nyazi.exe","handlingStrategy":"validation","validationCode":"#[cfg(windows)]\nfn cache_dir_ok() -> bool {\n    std::env::var_os(\"LOCALAPPDATA\").is_some_and(|v| std::path::Path::new(&v).is_absolute())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["windows","environment","cache","startup","panic"],"backgroundTag":null,"analyzedSha":"94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2","analyzedAt":"2026-08-16T09:56:24.836Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}