phiresky/ripgrep-all · error
Config file not found
Error message
Config file not found: {} What it means
This error is thrown by read_config_file in src/config.rs when the user explicitly provided a config file path override, but the resolved path override does not exist on disk. The library only auto-creates a default config when no path override is given; when a path override IS given, a missing file is treated as a hard error instead of silently creating a default. The error message interpolates the offending path so the developer can see exactly which file was not found.
Solutions
- Check that the path passed via the config override flag exists: run `ls -la <path>` (or the equivalent) to confirm the file is present.
- Fix typos or update the path to the actual config file location, e.g. use the repo's config/config.v1.json rather than a stale path.
- If the config lives in a fresh checkout, either restore the file or remove the override so the library falls back to writing/using the default config in config_dir.
- Run the command from the intended working directory (or pass an absolute path) so relative overrides resolve correctly.
Example fix
// before mytool --config ./confg/config.v1.json // after (typo fixed, and verify the file exists) ls ./config/config.v1.json && mytool --config ./config/config.v1.json
Defensive patterns
Strategy: validation
Validate before calling
fn ensure_config_exists(path: &str) -> Result<(), String> {
let p = std::path::Path::new(path);
if p.is_file() {
Ok(())
} else {
Err(format!("Config override does not exist: {}", path))
}
} Type guard
fn config_file_exists(path: &str) -> bool {
std::path::Path::new(path).is_file()
} Try / catch
// Rust: handle the anyhow error at the call site
match parse_args() {
Ok(args) => run(args),
Err(e) if e.to_string().starts_with("Config file not found:") => {
eprintln!("{} — falling back to default config", e);
run_with_default_config();
}
Err(e) => return Err(e),
} Prevention
- Validate the config path exists before invoking the CLI, e.g. in shell: `[ -f "$CONFIG" ] || { echo "missing config $CONFIG"; exit 1; }`.
- Use absolute paths for config overrides in scripts and CI so they are independent of the working directory.
- Commit or provision the config file (or a template) so fresh clones/CI runners always have it.
- Omit the override flag when you want the library's default-config creation behavior instead of a hard error.
When it happens
Trigger: Calling the CLI (via parse_args) with a --config style path override pointing to a file that does not exist, e.g. a typo in the path, a config file that was moved or deleted, or a relative path resolved against a different working directory.
Common situations: Typo in the config path flag; pointing at a config file in a repo that was gitignored and never created on a fresh clone; running from a different working directory so a relative path no longer resolves; CI environments where the config file was expected to be provisioned by a prior step that failed.
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.
AI-assisted analysis of phiresky/ripgrep-all@0f10fb926e (2026-09-10).
Data as JSON: /api/errors/f397b7a0ccaf04d0.
Report an issue: GitHub.
Appendix: source
Thrown at src/config.rs:300
format!("Could not read config file json {config_filename_str}")
})?;
let mut s = String::new();
json_comments::StripComments::new(raw.as_bytes())
.read_to_string(&mut s)
.context("strip comments")?;
s
};
{
// just for error messages, actual deserialization happens after merging with cmd args
serde_json::from_str::<RgaConfig>(&config_file_contents).with_context(|| {
format!("Error in config file {config_filename_str}: {config_file_contents}")
})?;
}
let config_json: serde_json::Value =
serde_json::from_str(&config_file_contents).context("Could not parse config json")?;
Ok((config_filename_str, config_json))
} else if let Some(p) = path_override.as_ref() {
Err(anyhow::anyhow!("Config file not found: {}", p))?
} else {
// write default config
std::fs::create_dir_all(config_dir)?;
let mut schemafile = File::create(config_dir.join("config.v1.schema.json"))?;
schemafile.write_all(
serde_json::to_string_pretty(&schemars::schema_for!(RgaConfig))?.as_bytes(),
)?;
let mut configfile = File::create(config_filename)?;
configfile.write_all(include_str!("../doc/config.default.jsonc").as_bytes())?;
Ok((
config_filename_str,
serde_json::Value::Object(Default::default()),
))
}
}
fn read_config_env() -> Result<Value> {View on GitHub (pinned to 0f10fb926e)