{"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/0e07a155371a6ce88ae53a2c00df940280c09a67/src/context/error.rs#L23-L59","documentation":"ConfigError::missing (error.rs:39-44) is produced when a required config key is requested but is not present in any source (config files, environment, or CLI). The message is 'missing config key `<key>`' with no definition (definition is None because no source provided it). This is the serde/`get::<T>()` path when a mandatory value is absent.","triggerScenarios":"Calling `gctx.get::<T>(\"some.required.key\")` (non-optional) when the key is unset everywhere; a manifest/config schema field that is mandatory but was never provided.","commonSituations":"Cargo-internal code or a cargo-library consumer fetching a required config value that the user never set; a feature expecting a config key added in a newer Cargo version.","solutions":["Provide the key in the appropriate config.toml, env var, or CLI flag as documented.","If the value is optional in your use case, use `gctx.get::<OptValue<T>>(key)` instead of the required form.","Check Cargo version compatibility for that key."],"exampleFix":"// before (consuming cargo as a library)\nlet jobs: u32 = gctx.get(\"build.jobs\")?;  // required, bails if unset\n// after\nlet jobs: Option<u32> = gctx.get(\"build.jobs\")?;  // optional","handlingStrategy":"validation","validationCode":"// When consuming cargo as a library, request optional values for keys\n// that may be unset:\nlet jobs: Option<u32> = gctx.get(\"build.jobs\")?;","typeGuard":null,"tryCatchPattern":"// Provide a default when a required key is missing:\nlet jobs: u32 = gctx.get(\"build.jobs\")\n    .unwrap_or_else(|_| Ok(default_jobs()))?;","preventionTips":["Prefer OptValue<T> / Option<T> for config keys that are not strictly required.","Document mandatory config keys prominently for users of your cargo-library tool.","Check the Cargo version that introduced a key before depending on it."],"tags":["config","missing-key","deserialization"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}