{"record":{"id":"017515891bb7ca48","repo":"vectordotdev/vector","slug":"tried-to-set-metadata-flag-key-but-already-existed-in-schema","errorCode":null,"errorMessage":"Tried to set metadata flag '{key}' but already existed in schema metadata for `{type_name}`.","messagePattern":"Tried to set metadata flag '(.+?)' but already existed in schema metadata for `(.+?)`\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/schema/helpers.rs","lineNumber":121,"sourceCode":"\n        if let Some(message) = metadata.deprecated_message() {\n            custom_map.insert(\n                \"deprecated_message\".to_string(),\n                serde_json::Value::String(message.to_string()),\n            );\n        }\n\n        for attribute in metadata.custom_attributes() {\n            match attribute {\n                CustomAttribute::Flag(key) => {\n                    match custom_map.insert(key.to_string(), Value::Bool(true)) {\n                        // Overriding a flag is fine, because flags are only ever \"enabled\", so there's\n                        // no harm to enabling it... again. Likewise, if there was no existing value,\n                        // it's fine.\n                        Some(Value::Bool(_)) | None => {}\n                        // Any other value being present means we're clashing with a different metadata\n                        // attribute, which is not good, so we have to bail out.\n                        _ => panic!(\n                            \"Tried to set metadata flag '{key}' but already existed in schema metadata for `{type_name}`.\"\n                        ),\n                    }\n                }\n                CustomAttribute::KeyValue { key, value } => {\n                    custom_map.entry(key.to_string())\n                        .and_modify(|existing_value| match existing_value {\n                            // We already have a flag entry for this key, which we cannot turn into an\n                            // array, so we panic in this particular case to signify the weirdness.\n                            Value::Bool(_) => {\n                                panic!(\"Tried to overwrite metadata flag '{key}' but already existed in schema metadata for `{type_name}` as a flag.\");\n                            },\n                            // The entry is already a multi-value KV pair, so just append the value.\n                            Value::Array(items) => {\n                                items.push(value.clone());\n                            },\n                            // The entry is not already a multi-value KV pair, so turn it into one.\n                            _ => {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/schema/helpers.rs#L103-L139","documentation":"When applying custom metadata attributes to a schema, boolean flag attributes (e.g. `#[configurable(metadata(...))]` style flags) are written into the schema's `custom` metadata map. If the key already holds a non-boolean, non-null value — meaning a different metadata attribute already claimed that key — the two attributes clash and the code panics rather than silently overwriting unrelated metadata.","triggerScenarios":"`apply_custom_attributes` (called from `apply_configurable_metadata`) processes a `CustomAttribute::Flag` whose key already exists in the schema's custom metadata map with a non-`Value::Bool` value (e.g. an array or string from a KV attribute), triggering the panic at lib/vector-config/src/schema/helpers.rs:121.","commonSituations":"Two different `#[configurable(metadata(...))]` attributes on the same type or field using the same key with different value kinds; a base type's metadata clashing with field-level metadata overrides.","solutions":["Rename one of the conflicting metadata keys so each attribute has a unique key","Remove the redundant/duplicate metadata attribute","Use matching value kinds (both flags) if the same key is intentionally set twice"],"exampleFix":"// before\n#[configurable(metadata(example = \"x\", example = true))]\n// after\n#[configurable(metadata(example = \"x\", deprecated = true))]","handlingStrategy":"validation","validationCode":"fn flags_unique(attrs: &[(String, String)]) -> bool {\n    let mut seen = std::collections::HashSet::new();\n    attrs.iter().all(|(k, _)| seen.insert(k.clone()))\n}\n// assert!(flags_unique(&metadata_attrs), \"duplicate metadata keys with differing kinds\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep metadata key names unique per type/field","Don't mix flag and KV attributes under the same key name","Review metadata attributes when copying definitions between types"],"tags":["rust","json-schema","metadata","proc-macro"],"backgroundTag":"conflicting-config-options","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}