{"record":{"id":"af95e7ca89d21181","repo":"rust-lang/cargo","slug":"missing-config-key","errorCode":null,"errorMessage":"missing config key `{}`","messagePattern":"missing config key `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/context/error.rs","lineNumber":41,"sourceCode":"    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        }\n    }\n\n    pub(super) fn with_key_context(\n        self,\n        key: &ConfigKey,\n        definition: Option<Definition>,\n    ) -> ConfigError {\n        ConfigError {\n            error: anyhow::Error::from(self)\n                .context(format!(\"could not load config key `{}`\", key)),\n            definition: definition,\n        }\n    }\n\n    pub(super) fn with_array_item_key_context(\n        self,","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/rust-lang/cargo/blob/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/context/error.rs#L23-L59","documentation":"`ConfigError::missing` is returned when a required config key is absent from all layers and has no default. Unlike a type error, there is no `Definition` (the field is `None`) because no source file ever provided the value.","triggerScenarios":"Cargo-internal code calls `get::<T>(&key)` for a key that must exist but wasn't set anywhere; e.g. a required `[registry]` token, or a path that defaults only in some profiles.","commonSituations":"First-time setup missing credentials; CI without `CARGO_REGISTRY_TOKEN`; a workspace that overrides defaults removing a required field.","solutions":["Set the missing key in the appropriate config layer (project `.cargo/config.toml`, user `~/.cargo/config.toml`, or env).","Use `cargo config get <key>` to confirm absence and where to add it.","Provide the value via the `--config <key>=<value>` CLI flag for one-off runs.","Check the error's surrounding context message for the full key path."],"exampleFix":"// before\n# error: missing config key `registry.default`\ncargo publish\n\n// after (.cargo/config.toml)\n[registry]\ndefault = \"crates-io\"","handlingStrategy":"validation","validationCode":"fn config_key_present(gctx: &GlobalContext, key: &str) -> bool {\n    gctx.get::<toml::Value>(key).is_ok()\n}","typeGuard":"null","tryCatchPattern":"match gctx.get::<String>(&key) {\n    Err(e) if e.to_string().contains(\"missing config key\") => use_default(&key),\n    r => r?,\n}","preventionTips":["Provide required keys in a checked-onboarding config template.","CI: assert `cargo config get <required-key>` returns a value.","Document required vs optional keys per environment."],"tags":["cargo","config","missing-key","toml"],"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"}