{"id":"c677f1fdc3d1a7db","repo":"rust-lang/cargo","slug":"invalid-configuration-for-key","errorCode":null,"errorMessage":"invalid configuration for key `{}`\n{}","messagePattern":"invalid configuration for key `(.+?)`\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":1155,"sourceCode":"    /// Low-level method for getting a config value as an `OptValue<HashMap<String, CV>>`.\n    ///\n    /// NOTE: This does not read from env. The caller is responsible for that.\n    fn get_table(&self, key: &ConfigKey) -> CargoResult<OptValue<HashMap<String, CV>>> {\n        match self.get_cv(key)? {\n            Some(CV::Table(val, definition)) => Ok(Some(Value { val, definition })),\n            Some(val) => self.expected(\"table\", key, &val),\n            None => Ok(None),\n        }\n    }\n\n    get_value_typed! {get_integer, i64, Integer, \"an integer\"}\n    get_value_typed! {get_bool, bool, Boolean, \"true/false\"}\n    get_value_typed! {get_string_priv, String, String, \"a string\"}\n\n    /// Generate an error when the given value is the wrong type.\n    fn expected<T>(&self, ty: &str, key: &ConfigKey, val: &CV) -> CargoResult<T> {\n        val.expected(ty, &key.to_string())\n            .map_err(|e| anyhow!(\"invalid configuration for key `{}`\\n{}\", key, e))\n    }\n\n    /// Update the instance based on settings typically passed in on\n    /// the command-line.\n    ///\n    /// This may also load the config from disk if it hasn't already been\n    /// loaded.\n    pub fn configure(\n        &mut self,\n        verbose: u32,\n        quiet: bool,\n        color: Option<&str>,\n        frozen: bool,\n        locked: bool,\n        offline: bool,\n        target_dir: &Option<PathBuf>,\n        unstable_flags: &[String],\n        cli_config: &[String],","sourceCodeStart":1137,"sourceCodeEnd":1173,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/mod.rs#L1137-L1173","documentation":"The internal helper GlobalContext::expected (mod.rs:1152-1156) wraps a typed config-value error (ConfigError::expected from error.rs) into 'invalid configuration for key `<key>`\\n<detail>' when a config key holds a value of the wrong type. The second line carries the underlying '`<key>` expected X, but found a Y' detail plus the definition.","triggerScenarios":"Any typed config read (get::<bool>, get::<i64>, get_table, etc.) where the stored value's type does not match, e.g. `[build] jobs = \"abc\"` (string instead of integer), or `[term] color = 1` where bool is expected.","commonSituations":"Misformatted config.toml; env var overriding a typed key with the wrong shape; version skew where a key's expected type changed.","solutions":["Read the two-line message: the key and the expected vs found types.","Correct the value in the offending source (the message's detail may name the file via the definition).","Check the Cargo config reference for the key's correct type and units."],"exampleFix":"# before (.cargo/config.toml)\n[build]\njobs = \"8\"   # string, integer expected -> invalid configuration\n# after\n[build]\njobs = 8","handlingStrategy":"validation","validationCode":"# Type-check known config keys against their expected types:\npython3 - <<'EOF'\nimport tomllib\ntry: d = tomllib.load(open('.cargo/config.toml','rb'))\nexcept FileNotFoundError: raise SystemExit(0)\nschema = {'build.jobs': int, 'build.panic': str, 'term.color': str}\ndef get(d, p):\n    for k in p.split('.'): d = d.get(k, {})\n    return d\nfor k, t in schema.items():\n    v = get(d, k)\n    if v and not isinstance(v, t): raise SystemExit(f'{k}: expected {t.__name__}')\nEOF","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match config value types to the Cargo reference exactly (int for jobs, bool for color where required, etc.).","Use `cargo config get <key>` to see the resolved value and its type.","Lint config.toml in CI."],"tags":["config","type-mismatch","config-value"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}