Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cargo/util/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}