{"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 asset directory\")\n\t\t}\n\t}\n\n\tpub fn state_dir() -> &'static PathBuf {\n\t\tstatic DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_state_dir);\n\t\t&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 DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_runtime_dir);\n\t\t&DIR\n\t}\n\n\tfn load_runtime_dir() -> PathBuf {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/sxyazi/yazi/blob/a541adde4e5b082719a0f21a87eb3eab071ece58/yazi-fs/src/xdg.rs#L54-L90","documentation":"Same OnceLock-cached resolution but for the state directory; on Windows it calls dirs::data_dir() and panics if None. dirs::data_dir() resolves %APPDATA% (Roaming), so None means APPDATA/USERPROFILE are missing. Yazi requires a state location, so this is an unrecoverable panic at first access.","triggerScenarios":"First access of the yazi_fs xdg state_dir on Windows when dirs::data_dir() returns None (APPDATA or USERPROFILE env vars unset).","commonSituations":"Launching yazi from a scheduler/service or a shell with sanitized environment on Windows; broken roaming profile configuration.","solutions":["Set APPDATA to an absolute path (e.g. %USERPROFILE%\\AppData\\Roaming) before launch","Ensure USERPROFILE is set for the account running yazi","Run yazi from an interactive user shell rather than a service context"],"exampleFix":"// before\nrunas /user:svc yazi.exe\n// after\nset \"APPDATA=C:\\Users\\svc\\AppData\\Roaming\"\nrunas /user:svc /env yazi.exe","handlingStrategy":"validation","validationCode":"if [ -z \"$APPDATA\" ] && [ -n \"$USERPROFILE\" ]; then export APPDATA=\"$USERPROFILE/AppData/Roaming\"; fi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep APPDATA set when spawning processes on Windows","Avoid runas/service contexts without /env","Test launch wrappers with `env -i` to catch stripped vars"],"tags":["windows","xdg","state-dir","panic","env"],"backgroundTag":"missing-appdata-env-var","analyzedSha":"a541adde4e5b082719a0f21a87eb3eab071ece58","analyzedAt":"2026-09-02T18:38:25.566Z","contentChangedAt":"2026-09-02T18:38:25.566Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}