From 2ed6ca8718f0b02dc728b5c6b12dff3bed8bfb73 Mon Sep 17 00:00:00 2001 From: Lars Erik Wik Date: Thu, 7 May 2026 09:39:18 +0200 Subject: [PATCH] Include path in config load error messages Read, parse, and "no config file found" errors now name the path or work directory, so users can tell which file is misbehaving without turning on debug logging. Signed-off-by: Lars Erik Wik --- src/config.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/config.rs b/src/config.rs index d4ceb9b..cdb3356 100644 --- a/src/config.rs +++ b/src/config.rs @@ -544,18 +544,22 @@ impl Config { } (true, false) => (toml_path, ConfigFormat::Toml), (false, true) => (json_path, ConfigFormat::Json), - (false, false) => bail!("no config file found (expected config.toml or config.json)"), + (false, false) => bail!( + "no config file found in '{}' (expected config.toml or config.json)", + work_dir.display() + ), }; log::debug!("Parsing config from file '{}'...", path.display()); - let content = fs::read_to_string(&path).context("failed to read config file")?; + let content = fs::read_to_string(&path) + .with_context(|| format!("failed to read config file '{}'", path.display()))?; let mut config: Config = match format { - ConfigFormat::Toml => { - toml::from_str(&content).context("failed to parse config TOML file")? - } - ConfigFormat::Json => { - serde_json::from_str(&content).context("failed to parse config JSON file")? - } + ConfigFormat::Toml => toml::from_str(&content).with_context(|| { + format!("failed to parse config TOML file '{}'", path.display()) + })?, + ConfigFormat::Json => serde_json::from_str(&content).with_context(|| { + format!("failed to parse config JSON file '{}'", path.display()) + })?, }; config.work_dir = work_dir.to_path_buf();