sxyazi/yazi · critical
Failed to get config directory
Error message
Failed to get config directory
What it means
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.
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
Example fix
// before
dirs::config_dir().map(|p| p.join("yazi\\config")).expect("Failed to get config directory")
// after
dirs::config_dir().map(|p| p.join("yazi\\config"))
.or_else(|| env::var_os("APPDATA").map(PathBuf::from).map(|p| p.join("yazi\\config")))
.unwrap_or_else(|| panic!("Failed to get config directory")) Defensive patterns
Strategy: fallback
Validate before calling
#[cfg(windows)]
let has_config_dir = std::env::var_os("APPDATA").is_some()
|| dirs::config_dir().is_some();
if !has_config_dir { eprintln!("APPDATA unresolvable; set APPDATA before launching"); } Type guard
fn windows_config_dir() -> Option<PathBuf> {
dirs::config_dir().map(|p| p.join("yazi\\config"))
.or_else(|| std::env::var_os("APPDATA").map(PathBuf::from))
} Try / catch
// expect() panics rather than returning Err, so pre-check:
match dirs::config_dir() {
Some(p) => p.join("yazi\\config"),
None => { eprintln!("Failed to get config directory"); std::process::exit(1); }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Running yazi as a Windows service or under an account with no roaming profile; a broken APPDATA known-folder entry; minimal/containerized Windows environments.
Related errors
- Failed to get asset directory
- Failed to get cache directory
- Failed to get state directory
- Unwinding must be enabled for Windows. Please use `cargo…
- at least one of `url` or `mime` must be specified
AI-assisted analysis of sxyazi/yazi@a541adde4e (2026-09-02).
Data as JSON: /api/errors/34dbf6e81db14aa0.
Report an issue: GitHub.
Appendix: source
Thrown at yazi-fs/src/xdg.rs:30
Self::runtime_dir();
Self::temp_dir();
}
pub fn config_dir() -> &'static PathBuf {
static DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_config_dir);
&DIR
}
fn load_config_dir() -> PathBuf {
if let Some(p) = env::var_os("YAZI_CONFIG_HOME").map(PathBuf::from)
&& p.is_absolute()
{
return p;
}
#[cfg(windows)]
{
dirs::config_dir().map(|p| p.join("yazi\\config")).expect("Failed to get config directory")
}
#[cfg(unix)]
{
env::var_os("XDG_CONFIG_HOME")
.map(PathBuf::from)
.filter(|p| p.is_absolute())
.map(|p| p.join("yazi"))
.or_else(|| dirs::home_dir().map(|h| h.join(".config/yazi")))
.expect("Failed to get config directory")
}
}
pub fn asset_dir() -> &'static PathBuf {
static DIR: LazyLock<PathBuf> = LazyLock::new(Xdg::load_asset_dir);
&DIR
}
fn load_asset_dir() -> PathBuf {View on GitHub (pinned to a541adde4e)