{"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 DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_config_dir);\n\t\t&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 asset_dir() -> &'static PathBuf {\n\t\tstatic DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_asset_dir);\n\t\t&DIR\n\t}\n\n\tfn load_asset_dir() -> PathBuf {","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/sxyazi/yazi/blob/a541adde4e5b082719a0f21a87eb3eab071ece58/yazi-fs/src/xdg.rs#L12-L48","documentation":"This is a panic (via .expect), not a returned error: on Windows, load_config_dir calls dirs::config_dir() and expects it to succeed with message 'Failed to get config directory'. dirs::config_dir() returns None when the %APPDATA% (CSIDL_APPDATA / FOLDERID_RoamingAppData) folder cannot be resolved, which is abnormal on Windows but possible in broken profiles or service contexts.","triggerScenarios":"Any call to Xdg::config_dir()/load_config_dir on a Windows system where dirs::config_dir() returns None — e.g., corrupted user profile, missing APPDATA environment/known-folder registration, or running from a service account without a user profile.","commonSituations":"Running yazi as a Windows service or under an account with no roaming profile; a broken APPDATA known-folder entry; minimal/containerized Windows environments.","solutions":["Ensure the process runs under a real interactive user account with a valid profile","Set/repair the APPDATA environment variable (e.g. APPDATA=C:\\Users\\<user>\\AppData\\Roaming)","Restore the Roaming known folder registration or provide an explicit config dir override"],"exampleFix":"// before\ndirs::config_dir().map(|p| p.join(\"yazi\\\\config\")).expect(\"Failed to get config directory\")\n// after\ndirs::config_dir().map(|p| p.join(\"yazi\\\\config\"))\n    .or_else(|| env::var_os(\"APPDATA\").map(PathBuf::from).map(|p| p.join(\"yazi\\\\config\")))\n    .unwrap_or_else(|| panic!(\"Failed to get config directory\"))","handlingStrategy":"fallback","validationCode":"#[cfg(windows)]\nlet has_config_dir = std::env::var_os(\"APPDATA\").is_some()\n    || dirs::config_dir().is_some();\nif !has_config_dir { eprintln!(\"APPDATA unresolvable; set APPDATA before launching\"); }","typeGuard":"fn windows_config_dir() -> Option<PathBuf> {\n    dirs::config_dir().map(|p| p.join(\"yazi\\\\config\"))\n        .or_else(|| std::env::var_os(\"APPDATA\").map(PathBuf::from))\n}","tryCatchPattern":"// expect() panics rather than returning Err, so pre-check:\nmatch dirs::config_dir() {\n    Some(p) => p.join(\"yazi\\\\config\"),\n    None => { eprintln!(\"Failed to get config directory\"); std::process::exit(1); }\n}","preventionTips":["Run under an interactive user account with a valid Windows profile","Keep the APPDATA environment variable intact","Avoid launching the app from service contexts without a user profile"],"tags":["windows","config","environment","panic"],"backgroundTag":"missing-config-directory","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"}