Skip to content

Commit

Permalink
fix(config): Improve the error for partial-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Apr 2, 2024
1 parent da0d826 commit 65379a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cargo/util/context/mod.rs
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
18 changes: 16 additions & 2 deletions tests/testsuite/config.rs
Expand Up @@ -1825,7 +1825,14 @@ fn incomplete_cli() {
.arg("--config=term.progress.width=2")
.with_status(101)
.with_stdout("")
.with_stderr("[ERROR] missing field `when`")
.with_stderr(
"\
error: failed to read `term` config field
Caused by:
missing field `when`
",
)
.run();
}

Expand All @@ -1852,6 +1859,13 @@ fn incomplete_env() {
.env("CARGO_TERM_PROGRESS_WIDTH", "2")
.with_status(101)
.with_stdout("")
.with_stderr("[ERROR] missing field `when`")
.with_stderr(
"\
error: failed to read `term` config field
Caused by:
missing field `when`
",
)
.run();
}

0 comments on commit 65379a2

Please sign in to comment.