{"record":{"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":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/context/mod.rs","lineNumber":1144,"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":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/rust-lang/cargo/blob/98a09e7e7d62850f14e5b6132101fc1edd19a16f/src/context/mod.rs#L1126-L1162","documentation":"Thrown by ConfigValue::expected() (called via get_integer, get_bool, get_string, etc.) when a configuration value read from config.toml, environment variables, or CLI flags does not match the expected Rust type for that configuration key. The error message names the key and describes the type mismatch.","triggerScenarios":"Providing a config value of the wrong type for a known key, e.g. setting an integer key to a string, a boolean key to an integer, or a string key to a table.","commonSituations":"Writing `verbose = \"yes\"` instead of `verbose = true` in config.toml. Setting a CARGO_* environment variable to a value that cannot be parsed as the expected type. CLI flag with wrong value type.","solutions":["Check the error message which names the specific key and the expected type","Consult Cargo's configuration documentation for the correct type of each key","Fix the value in config.toml, the environment variable, or the CLI flag to match the expected type"],"exampleFix":"# before (config.toml)\n[net]\nretry = \"3\"\n\n# after\n[net]\nretry = 3","handlingStrategy":"validation","validationCode":"// Validate config value types before loading\nfn validate_config_toml(path: &Path) -> Result<(), String> {\n    let content = std::fs::read_to_string(path).map_err(|e| e.to_string())?;\n    let toml_val: toml::Value = toml::from_str(&content).map_err(|e| e.to_string())?;\n    // Check known integer keys are integers, boolean keys are booleans, etc.\n    if let Some(table) = toml_val.as_table() {\n        if let Some(net) = table.get(\"net\").and_then(|v| v.as_table()) {\n            if let Some(retry) = net.get(\"retry\") {\n                if !retry.is_integer() {\n                    return Err(\"net.retry must be an integer\".into());\n                }\n            }\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Consult Cargo's config documentation for the expected type of each key","Use cargo config check or similar validation tools if available","When setting values via environment variables, ensure they match the expected parsed type"],"tags":["configuration","type-mismatch","config-toml"],"backgroundTag":null,"analyzedSha":"98a09e7e7d62850f14e5b6132101fc1edd19a16f","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}