{"record":{"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/context/error.rs#L7-L43","documentation":"`ConfigError::expected` constructs a typed error when a config value's type doesn't match the declared type for its key (e.g. `[build] jobs` declared as integer but found a boolean). It includes the key, the expected type name, and `found.desc()` (the actual TOML type), plus the `Definition` pointing at the source file:line.","triggerScenarios":"Defining a config key with the wrong TOML type: `build.jobs = true`, `term.color = \"yes\"` (expected enum), `[net.git-fetch-with-cli] = \"maybe\"` instead of bool.","commonSituations":"Hand-editing `.cargo/config.toml`; copying examples from docs with a different schema version; typos turning values into sections or vice versa.","solutions":["Open the `definition` file:line from the error and change the value to the expected type.","Consult `cargo help config` / the manifest reference for the field's accepted type.","Validate with `cargo config get <key>` after fixing.","Use a TOML linter or LSP to catch schema mismatches early."],"exampleFix":"// before (.cargo/config.toml)\n[term]\ncolor = \"yes\"   # expected bool\n\n// after\n[term]\ncolor = true","handlingStrategy":"validation","validationCode":"fn config_value_matches_type(key: &str, v: &toml::Value, expected: ExpectedType) -> bool {\n    matches!((v, expected), (toml::Value::Boolean(_), ExpectedType::Bool) | (toml::Value::Integer(_), ExpectedType::Int) | (toml::Value::String(_), ExpectedType::Str))\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use a schema-validated config loader for `.cargo/config.toml`.","Keep examples aligned with the current Cargo reference.","Run `cargo config get` after manual edits."],"tags":["cargo","config","toml","type-mismatch","schema"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}