{"id":"1cdf43590d45084a","repo":"rust-lang/cargo","slug":"expected-but-found-a","errorCode":null,"errorMessage":"`{}` expected {}, but found a {}","messagePattern":"`(.+?)` expected (.+?), but found a (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/error.rs","lineNumber":25,"sourceCode":"\n/// Internal error for serde errors.\n#[derive(Debug)]\npub struct ConfigError {\n    error: anyhow::Error,\n    definition: Option<Definition>,\n}\n\nimpl ConfigError {\n    pub(super) fn new(message: String, definition: Definition) -> ConfigError {\n        ConfigError {\n            error: anyhow::Error::msg(message),\n            definition: Some(definition),\n        }\n    }\n\n    pub(super) fn expected(key: &ConfigKey, expected: &str, found: &ConfigValue) -> ConfigError {\n        ConfigError {\n            error: anyhow::anyhow!(\n                \"`{}` expected {}, but found a {}\",\n                key,\n                expected,\n                found.desc()\n            ),\n            definition: Some(found.definition().clone()),\n        }\n    }\n\n    pub(super) fn is_missing_field(&self) -> bool {\n        self.error.downcast_ref::<MissingFieldError>().is_some()\n    }\n\n    pub(super) fn missing(key: &ConfigKey) -> ConfigError {\n        ConfigError {\n            error: anyhow::anyhow!(\"missing config key `{}`\", key),\n            definition: None,\n        }","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/error.rs#L7-L43","documentation":"During config deserialization, when a value's type does not match what the schema expects for a key, ConfigError::expected (error.rs:23-33) builds '`<key>` expected <expected>, but found a <found.desc()>'. The definition of the offending value is attached. This is the underlying type-error behind many 'invalid configuration for key' messages.","triggerScenarios":"A config key that the schema declares as one type receives another, e.g. `[net] retry = \"yes\"` where retry is a bool, or `profiles.dev opt-level = \"fast\"`. Produced by ConfigValue accessors (i64/string/table/bool) and the typed `get` deserializer.","commonSituations":"Typos in config.toml units; passing a string where an integer/bool/list is expected; mismatched value shapes between env var and config file.","solutions":["Read the message for the key name and the expected vs found types.","Consult the config reference for that key's expected type and fix the value accordingly.","Locate the source via the attached definition (which file/env set it)."],"exampleFix":"# before\n[profile.release]\nopt-level = \"fast\"   # string, but integer expected\n# after\n[profile.release]\nopt-level = 3","handlingStrategy":"validation","validationCode":"# Lint config.toml value types against the schema before building.\n# Example: jobs must be an integer\npython3 -c \"import tomllib; d=tomllib.load(open('.cargo/config.toml','rb'));\\\n  assert isinstance(d.get('build',{}).get('jobs',0), int)\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cross-check config values against the Cargo config reference types.","Validate config.toml in CI with a linter/schema checker.","Avoid quoting numeric/boolean values in TOML."],"tags":["config","type-mismatch","deserialization","config-value"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}