lsd-rs/lsd · error
Provided file path is invalid
Error message
Provided file path is invalid
What it means
In main, when --config <path> is supplied, Config::from_file(path) is unwrapped with .expect("Provided file path is invalid"). from_file returns None when the path cannot be read or the file fails to parse into a Config, so this panic means the user passed a config path that does not exist, is unreadable, or contains invalid YAML.
Source
Thrown at src/main.rs:122
std::process::exit(0);
}
}
};
}
fn main() {
let cli = Cli::parse_from(wild::args_os());
// Handle --generate-config flag
if cli.generate_config {
generate_default_config();
std::process::exit(0);
}
let config = if cli.ignore_config {
Config::with_none()
} else if let Some(path) = &cli.config_file {
Config::from_file(path).expect("Provided file path is invalid")
} else {
Config::default()
};
let flags = Flags::configure_from(&cli, &config).unwrap_or_else(|err| err.exit());
let core = Core::new(flags);
let exit_code = core.run(cli.inputs);
std::process::exit(exit_code as i32);
}
fn generate_default_config() {
use crate::config_file;
// Print the default config to stdout without the leading '---'
let config = config_file::DEFAULT_CONFIG.trim_start_matches("---\n");
println!("{}", config);
}
View on GitHub (pinned to 4b6c14a110)
Solutions
- Verify the path exists and is readable: ls -l <path> / cat <path>; fix typos and permissions.
- Validate the file's YAML parses as eza config (compare with the documented config format / default config).
- Update renamed or removed config keys to match your installed eza version (check eza --help or release notes).
- As a workaround, start without --config (use Config::default()) or with --ignore-config.
Example fix
// before
let config = Config::from_file(path).expect("Provided file path is invalid");
// after
if !path.is_file() {
eprintln!("config file not found: {}", path.display());
std::process::exit(1);
}
let config = Config::from_file(path).unwrap_or_else(|| {
eprintln!("failed to parse config: {}", path.display());
std::process::exit(1);
}); Defensive patterns
Strategy: validation
Validate before calling
let path = std::path::Path::new(cli.config_file);
if !path.is_file() {
eprintln!("config file not found: {}", path.display());
std::process::exit(1);
}
let contents = std::fs::read_to_string(path)
.expect("config file unreadable");
assert!(serde_yaml::from_str::<Config>(&contents).is_ok(), "invalid config YAML"); Type guard
fn is_valid_config_path(p: &str) -> bool {
std::path::Path::new(p).is_file()
} Try / catch
let config = Config::from_file(path).unwrap_or_else(|| {
eprintln!("Provided file path is invalid: {}", path.display());
std::process::exit(1);
}); Prevention
- Always check the config path exists with is_file() before passing --config.
- Quote variables in shell to avoid empty expansions: eza --config "$CONFIG".
- Validate the config YAML with a parser or eza --ignore-config A/B test after edits.
- Re-check config keys after upgrading eza; remove renamed/deprecated options.
When it happens
Trigger: Running eza with eza --config <path> where the path is missing, has wrong permissions, is a directory, or the file contains YAML that does not deserialize into Config.
Common situations: Typo in the config path; shell variable expanding to empty ($XDG_CONFIG_HOME unset); config written for an older eza version with renamed/removed keys; pointing --config at a directory or a config for a different tool.
Understand the failure class
Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.
Related errors
AI-assisted analysis of lsd-rs/lsd@4b6c14a110 (2026-09-04).
Data as JSON: /api/errors/2028d04f67ee0d26.
Report an issue: GitHub.