Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env var configuration errors may contain duplicate error messages #7782

Open
alexcrichton opened this issue Jan 8, 2020 · 0 comments
Open
Labels
A-configuration Area: cargo config files and env vars A-diagnostics Area: Error and warning messages generated by Cargo itself. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.

Comments

@alexcrichton
Copy link
Member

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 --

ConfigError::from(e).with_key_context(&self.de.key, self.definition.clone())
. 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.

@alexcrichton alexcrichton added the A-configuration Area: cargo config files and env vars label Jan 8, 2020
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jan 9, 2020
There's an existing bug (rust-lang#7782) in Cargo which exacerbates the issue
here but in general having a stack of errors is a bit easier to read and
work with than having a big long error message.
@epage epage added A-diagnostics Area: Error and warning messages generated by Cargo itself. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing. labels Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars A-diagnostics Area: Error and warning messages generated by Cargo itself. S-needs-mentor Status: Issue or feature is accepted, but needs a team member to commit to helping and reviewing.
Projects
None yet
Development

No branches or pull requests

2 participants