Env var configuration errors may contain duplicate error messages
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Playing around a bit today, I saw:
$ CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER=1 cargo +nightly build
error: error in environment variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER`: could not load config key `target.x86_64-unknown-linux-gnu.runner`: error in environment variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER`: could not load config key `target.x86_64-unknown-linux-gnu.runner`: failed to deserialize, expected a string or array of strings: data did not match any variant of untagged enum Target
Here the "could not load key..." is duplicated in the error message, but probably shouldn't be! Doing some debugging this is related to ConfigError::with_key_context and it's called twice on the stack both from this location -- https://github.com/rust-lang/cargo/blob/6dd57b2045f37fc8172176e333d0fcd3e07cdea1/src/cargo/util/config/de.rs#L472. The stack trace in the inner call looks like:
cargo::util::config::ConfigError::with_key_context (self=..., key=0x7ffffffed218, definition=...) at src/cargo/util/config/mod.rs:1239
1 -> 0x00005555562485c3 in <cargo::util::config::de::ValueDeserializer as serde::de::MapAccess>::next_value_seed::{{closure}} (e=...) at src/cargo/util/config/de.rs:472
0x00005555560edb31 in core::result::Result<T,E>::map_err (self=..., op=...) at /rustc/85976442558bf2d09cec3aa49c9c9ba86fb15c1f/src/libcore/result.rs:606
0x000055555624426b in <cargo::util::config::de::ValueDeserializer as serde::de::MapAccess>::next_value_seed (self=0x7ffffffed1f0, seed=...) at src/cargo/util/config/de.rs:471
0x000055555621ab5c in serde::de::MapAccess::next_value (self=0x7ffffffed1f0) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.104/src/de/mod.rs:1847
0x000055555605075a in <<cargo::util::config::value::Value<T> as serde::de::Deserialize>::deserialize::ValueVisitor<T> as serde::de::Visitor>::visit_map (self=..., visitor=...) at src/cargo/util/config/value.rs:140
0x000055555622cac8 in <cargo::util::config::de::Deserializer as serde::de::Deserializer>::deserialize_struct (self=..., name=..., fields=..., visitor=...) at src/cargo/util/config/de.rs:141
0x000055555604f30a in <cargo::util::config::value::Value<T> as serde::de::Deserialize>::deserialize (deserializer=...) at src/cargo/util/config/value.rs:151
0x000055555654854c in <cargo::util::config::path::PathAndArgs as serde::de::Deserialize>::deserialize (deserializer=...) at src/cargo/util/config/path.rs:58
0x0000555555f7204b in <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize (self=..., deserializer=...) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.104/src/de/mod.rs:786
2 -> 0x000055555624602d in <cargo::util::config::de::ValueDeserializer as serde::de::MapAccess>::next_value_seed (self=0x7ffffffee400, seed=...) at src/cargo/util/config/de.rs:471
0x000055555621afac in serde::de::MapAccess::next_value (self=0x7ffffffee400) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.104/src/de/mod.rs:1847
0x00005555560522d3 in <<cargo::util::config::value::Value<T> as serde::de::Deserialize>::deserialize::ValueVisitor<T> as serde::de::Visitor>::visit_map (self=..., visitor=...) at src/cargo/util/config/value.rs:140
0x000055555622ed48 in <cargo::util::config::de::Deserializer as serde::de::Deserializer>::deserialize_struct (self=..., name=..., fields=..., visitor=...) at src/cargo/util/config/de.rs:141
0x000055555604f20a in <cargo::util::config::value::Value<T> as serde::de::Deserialize>::deserialize (deserializer=...) at src/cargo/util/config/value.rs:151
0x000055555621473f in <serde::de::impls::OptionVisitor<T> as serde::de::Visitor>::visit_some (self=..., deserializer=...) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.104/src/de/impls.rs:621
0x000055555622b75e in <cargo::util::config::de::Deserializer as serde::de::Deserializer>::deserialize_option (self=..., visitor=...) at src/cargo/util/config/de.rs:120
0x00005555558bc2d9 in serde::de::impls::<impl serde::de::Deserialize for core::option::Option<T>>::deserialize (deserializer=...) at /home/alex/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.104/src/de/impls.rs:641
0x000055555648f746 in cargo::util::config::Config::get (self=0x7fffffffd180, key=...) at src/cargo/util/config/mod.rs:1121
0x0000555556481ea6 in cargo::util::config::target::load_target_triple (config=0x7fffffffd180, triple=...) at src/cargo/util/config/target.rs:74
0x000055555640aa0f in cargo::util::config::Config::target_cfg_triple (self=0x7fffffffd180, target=...) at src/cargo/util/config/mod.rs:1087
0x00005555560190b7 in cargo::core::compiler::build_context::BuildContext::new (ws=0x7fffffff9c68, packages=0x7fffffff3af0, config=0x7fffffffd180, build_config=0x7fffffffa198, profiles=0x5555577833a8, units=0x7fffffff5158, extra_compiler_args=...) at src/cargo/core/compiler/build_context/mod.rs:67
0x0000555556590834 in cargo::ops::cargo_compile::compile_ws (ws=0x7fffffff9c68, options=0x7fffffffa190, exec=0x7fffffff9b98) at src/cargo/ops/cargo_compile.rs:389
0x000055555658e7f5 in cargo::ops::cargo_compile::compile_with_exec (ws=0x7fffffff9c68, options=0x7fffffffa190, exec=0x7fffffff9b98) at src/cargo/ops/cargo_compile.rs:259
0x000055555658e6b0 in cargo::ops::cargo_compile::compile (ws=0x7fffffff9c68, options=0x7fffffffa190) at src/cargo/ops/cargo_compile.rs:248
0x00005555557a3a1a in cargo::commands::build::exec (config=0x7fffffffd180, args=0x55555769c4a8) at src/bin/cargo/commands/build.rs:72
0x00005555557d7291 in cargo::cli::execute_subcommand (config=0x7fffffffd180, cmd=..., subcommand_args=0x55555769c4a8) at src/bin/cargo/cli.rs:197
0x00005555557d5227 in cargo::cli::main (config=0x7fffffffd180) at src/bin/cargo/cli.rs:107
0x0000555555791da6 in cargo::main () at src/bin/cargo/main.rs:39
(line numbers relative to https://github.com/rust-lang/cargo/tree/6dd57b2045f37fc8172176e333d0fcd3e07cdea1)
I wanted to write this down but I'm honestly not sure there's much we can do about this. This is extremely specific I believe and crops up because there's two layered Value<T> instances being deserialized. One is the outer OptValue type and one is inside the PathAndArgs type. I don't think that the outer type knows that the context was already attached, so it ends up getting attached twice.
This looks like it's pretty local to this one specific key, so it's probably fine if we don't prioritize this too much.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the duplicate message with the CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER=1 cargo +nightly build command, then read src/cargo/util/config/de.rs around line 472 and ConfigError::with_key_context in src/cargo/util/config/mod.rs. Compare the layered deserialization paths in src/cargo/util/config/target.rs and path.rs; done means the configuration error reports the key context only once.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100