diff --git a/src/cargo/util/context/mod.rs b/src/cargo/util/context/mod.rs index f38fbd3df53..5f2e7ec3909 100644 --- a/src/cargo/util/context/mod.rs +++ b/src/cargo/util/context/mod.rs @@ -1939,7 +1939,7 @@ impl GlobalContext { key: ConfigKey::from_str(key), env_prefix_ok: true, }; - T::deserialize(d).map_err(|e| e.into()) + T::deserialize(d).with_context(|| format!("failed to read `{key}` config field")) } /// Obtain a [`Path`] from a [`Filesystem`], verifying that the diff --git a/tests/testsuite/config.rs b/tests/testsuite/config.rs index 39fcee2cd73..52b714e6359 100644 --- a/tests/testsuite/config.rs +++ b/tests/testsuite/config.rs @@ -1801,3 +1801,71 @@ fn trim_paths_parsing() { let trim_paths: TomlTrimPaths = gctx.get("profile.dev.trim-paths").unwrap(); assert_eq!(trim_paths, expected, "failed to parse {val}"); } + +#[cargo_test] +fn incomplete_cli() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + rust-version = "1.1.1" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .arg("--config=term.progress.width=2") + .with_status(101) + .with_stdout("") + .with_stderr( + "\ +error: failed to read `term` config field + +Caused by: + missing field `when` +", + ) + .run(); +} + +#[cargo_test] +fn incomplete_env() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2015" + authors = [] + rust-version = "1.1.1" + [[bin]] + name = "foo" + "#, + ) + .file("src/main.rs", "fn main() {}") + .build(); + + p.cargo("check") + .env("CARGO_TERM_PROGRESS_WIDTH", "2") + .with_status(101) + .with_stdout("") + .with_stderr( + "\ +error: failed to read `term` config field + +Caused by: + missing field `when` +", + ) + .run(); +}