{"record":{"id":"9b7e608da465c4d4","repo":"rust-lang/cargo","slug":"missing-field","errorCode":null,"errorMessage":"missing field `{}`","messagePattern":"missing field `(.+?)`","errorType":"exception","errorClass":"MissingFieldError","httpStatus":null,"severity":"error","filePath":"src/context/error.rs","lineNumber":107,"sourceCode":"impl fmt::Display for MissingFieldError {\n    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n        write!(f, \"missing field `{}`\", self.0)\n    }\n}\n\nimpl std::error::Error for MissingFieldError {}\n\nimpl serde::de::Error for ConfigError {\n    fn custom<T: fmt::Display>(msg: T) -> Self {\n        ConfigError {\n            error: anyhow::Error::msg(msg.to_string()),\n            definition: None,\n        }\n    }\n\n    fn missing_field(field: &'static str) -> Self {\n        ConfigError {\n            error: anyhow::Error::new(MissingFieldError(field.to_string())),\n            definition: None,\n        }\n    }\n}\n\nimpl From<anyhow::Error> for ConfigError {\n    fn from(error: anyhow::Error) -> Self {\n        ConfigError {\n            error,\n            definition: None,\n        }\n    }\n}\n","sourceCodeStart":89,"sourceCodeEnd":121,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/context/error.rs#L89-L121","documentation":"`ConfigError` implements `serde::de::Error`. The `missing_field` method is invoked by serde's derive machinery when a struct field declared required (non-optional, no `default`) is absent during deserialization. It wraps a `MissingFieldError(field.to_string())` into an `anyhow::Error` with `definition: None`. This is Cargo's config-deserialization path surfacing a missing required key as a typed error.","triggerScenarios":"Deserializing a Cargo config value (table) into a struct where a required field is absent. Serde invokes `<ConfigError as serde::de::Error>::missing_field(\"FieldName\")`, producing this error before any definition-location context is attached.","commonSituations":"A config table missing a mandatory key (e.g. a registry entry without its required field), schema changes between Cargo versions that make a previously-optional field required, or malformed/legacy config files.","solutions":["Add the missing field named in the error to the relevant config table.","Check the Cargo version's expected schema for that config section and supply all required keys.","Validate the config file against the documented structure for your Cargo version."],"exampleFix":"# before — registry entry missing required field\n[registries.myreg]\nindex = \"https://example.com/crates/\"\n# (missing a required field reported by the error)\n\n# after — add the field named in the error\n[registries.myreg]\nindex = \"https://example.com/crates/\"\ntoken = \"...\"","handlingStrategy":"validation","validationCode":"// before deserializing a config table, ensure required fields are present\nfn has_required(tbl: &toml::value::Table, required: &[&str]) -> Result<(), String> {\n    for k in required {\n        if !tbl.contains_key(*k) { return Err(format!(\"missing field `{k}`\")); }\n    }\n    Ok(())\n}\n// validate against the schema for your Cargo version, then deserialize","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate config tables against the documented schema before deserialization.","After Cargo upgrades, review changelogs for newly-required fields.","Use a TOML schema/linter in CI to catch missing keys early."],"tags":["config","serde","deserialization","missing-field","cargo"],"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"}