{"record":{"id":"34dbf6e81db14aa0","repo":"sxyazi/yazi","slug":"failed-to-get-config-directory","errorCode":null,"errorMessage":"Failed to get config directory","messagePattern":"Failed to get config directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"yazi-fs/src/xdg.rs","lineNumber":30,"sourceCode":"\t\tSelf::runtime_dir();\n\t\tSelf::temp_dir();\n\t}\n\n\tpub fn config_dir() -> &'static PathBuf {\n\t\tstatic ONCE: OnceLock<PathBuf> = OnceLock::new();\n\t\tONCE.get_or_init(Self::load_config_dir)\n\t}\n\n\tfn load_config_dir() -> PathBuf {\n\t\tif let Some(p) = env::var_os(\"YAZI_CONFIG_HOME\").map(PathBuf::from)\n\t\t\t&& p.is_absolute()\n\t\t{\n\t\t\treturn p;\n\t\t}\n\n\t\t#[cfg(windows)]\n\t\t{\n\t\t\tdirs::config_dir().map(|p| p.join(\"yazi\\\\config\")).expect(\"Failed to get config directory\")\n\t\t}\n\t\t#[cfg(unix)]\n\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 {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sxyazi/yazi/blob/94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2/yazi-fs/src/xdg.rs#L12-L48","documentation":"Windows branch of Xdg::load_config_dir: panics via expect when YAZI_CONFIG_HOME is not set to an absolute path and dirs::config_dir() (the Roaming AppData root, %APPDATA%) returns None, so there is no base to join \"yazi\\config\" onto. Evaluated once per process through a OnceLock at startup (Xdg::load).","triggerScenarios":"First call to Xdg::config_dir() on Windows with APPDATA unset, empty, or stripped — typical for SYSTEM/service accounts without a roaming profile, hardened CI runners, or wrappers that sanitize the environment.","commonSituations":"Running yazi/ya as a Windows service or scheduled task under SYSTEM; CI containers on Windows with a mutilated environment; APPDATA removed by an env-cleaning launcher.","solutions":["Set YAZI_CONFIG_HOME to an absolute path — it short-circuits the whole Windows lookup","Restore a valid APPDATA for the account, or run under a normal interactive user profile instead of SYSTEM","For services and scheduled tasks, wrap the launch in a script that sets APPDATA or YAZI_CONFIG_HOME first","Verify with `echo %APPDATA%` in the exact context that starts yazi"],"exampleFix":"REM before: APPDATA unset -> panic \"Failed to get config directory\"\nset YAZI_CONFIG_HOME=C:\\Users\\me\\.config\\yazi\nyazi.exe","handlingStrategy":"validation","validationCode":"#[cfg(windows)]\nfn config_dir_ok() -> bool {\n    std::env::var_os(\"YAZI_CONFIG_HOME\").is_some_and(|v| std::path::Path::new(&v).is_absolute())\n        || std::env::var_os(\"APPDATA\").is_some_and(|v| std::path::Path::new(&v).is_absolute())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set an absolute YAZI_CONFIG_HOME in service/CI contexts on Windows","Never run yazi under SYSTEM without APPDATA defined","Check `echo %APPDATA%` in the exact launching context before startup"],"tags":["windows","environment","startup","panic","config"],"backgroundTag":null,"analyzedSha":"94abcfa92f4ad3f0a1aef6c1ea083cfb8aa6c8c2","analyzedAt":"2026-08-16T09:56:24.836Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}