{"record":{"id":"748364828b0cd7ee","repo":"sxyazi/yazi","slug":"failed-to-get-state-directory","errorCode":null,"errorMessage":"Failed to get state directory","messagePattern":"Failed to get state directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"yazi-fs/src/xdg.rs","lineNumber":72,"sourceCode":"\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 {\n\t\t#[cfg(windows)]\n\t\t{\n\t\t\tdirs::data_dir().map(|p| p.join(\"yazi\\\\state\")).expect(\"Failed to get state directory\")\n\t\t}\n\t\t#[cfg(unix)]\n\t\t{\n\t\t\tenv::var_os(\"XDG_STATE_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(\".local/state/yazi\")))\n\t\t\t\t.expect(\"Failed to get state directory\")\n\t\t}\n\t}\n\n\tpub fn runtime_dir() -> &'static PathBuf {\n\t\tstatic ONCE: OnceLock<PathBuf> = OnceLock::new();\n\t\tONCE.get_or_init(Self::load_runtime_dir)\n\t}\n\n\tfn load_runtime_dir() -> PathBuf {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/sxyazi/yazi/blob/94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2/yazi-fs/src/xdg.rs#L54-L90","documentation":"Windows branch of Xdg::load_state_dir: panics via expect when dirs::data_dir() — the Roaming AppData root (%APPDATA%) — returns None, so the \"yazi\\state\" join cannot happen. yazi keeps persistent state (cursor position, tabs, plugin state) under this directory; it is resolved once per process at startup.","triggerScenarios":"First call to Xdg::state_dir() on Windows with APPDATA unset or unresolvable: SYSTEM/service accounts without a roaming profile, sanitized CI environments.","commonSituations":"Running yazi or ya as a scheduled task/service under SYSTEM; CI runners on Windows that strip APPDATA; group policies removing the roaming profile root.","solutions":["Restore a valid APPDATA for the account running yazi","Use an interactive user profile, or wrap the launch so APPDATA is set","Verify with `echo %APPDATA%` in the launching context","If APPDATA cannot be restored, run yazi from a normal user session instead of the stripped context"],"exampleFix":"REM before: APPDATA unset -> panic \"Failed to get state directory\"\nset APPDATA=C:\\Users\\me\\AppData\\Roaming\nyazi.exe","handlingStrategy":"validation","validationCode":"#[cfg(windows)]\nfn state_dir_ok() -> bool {\n    std::env::var_os(\"APPDATA\").is_some_and(|v| std::path::Path::new(&v).is_absolute())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set APPDATA in scheduled-task and service wrappers on Windows","Avoid SYSTEM for yazi workloads; use a profile-backed account","Check `echo %APPDATA%` before startup in the same context"],"tags":["windows","environment","state","startup","panic"],"backgroundTag":null,"analyzedSha":"94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2","analyzedAt":"2026-08-16T09:56:24.836Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}