{"record":{"id":"5e2a3d5f09f9c107","repo":"vectordotdev/vector","slug":"tried-to-overwrite-metadata-flag-key-but-already-existed-in","errorCode":null,"errorMessage":"Tried to overwrite metadata flag '{key}' but already existed in schema metadata for `{type_name}` as a flag.","messagePattern":"Tried to overwrite metadata flag '(.+?)' but already existed in schema metadata for `(.+?)` as a flag\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config/src/schema/helpers.rs","lineNumber":132,"sourceCode":"                    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                            _ => {\n                                let taken_existing_value = std::mem::replace(existing_value, Value::Null);\n                                *existing_value = Value::Array(vec![taken_existing_value, value.clone()]);\n                            },\n                        })\n                        .or_insert(value.clone());\n                }\n            }\n        }\n\n        custom_map.len()\n    };","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config/src/schema/helpers.rs#L114-L150","documentation":"The mirror case of the flag clash: a key/value (array-capable) metadata attribute is being applied, but the key already exists in the schema's custom metadata map as a boolean flag. A flag cannot be converted into a multi-value array, so `apply_custom_attributes` panics to surface the inconsistent attribute combination instead of silently discarding data.","triggerScenarios":"`apply_custom_attributes` processes a `CustomAttribute::KeyValue` whose key already maps to `Value::Bool` in the schema's custom metadata map (set by an earlier flag attribute), hitting the panic at lib/vector-config/src/schema/helpers.rs:132 while building the schema for `type_name`.","commonSituations":"Combining a flag attribute and a KV attribute with the same key (e.g. both named `example`) on one type/field; parent-type metadata colliding with field-level metadata of the same key name.","solutions":["Rename one of the attributes so the keys don't collide","Remove the duplicate attribute","Use the same attribute kind (both KV or both flag) if the key must be shared"],"exampleFix":"// before\n#[configurable(metadata(deprecated, example = \"foo\"))]\n// after\n#[configurable(metadata(deprecated, examples = \"foo\"))]","handlingStrategy":"validation","validationCode":"fn no_flag_kv_collision(attrs: &[(&str, bool /* is_flag */)]) -> bool {\n    let mut keys = std::collections::HashMap::new();\n    attrs.iter().all(|(k, flag)| {\n        keys.insert(k.to_string(), *flag).map_or(true, |prev| prev == *flag)\n    })\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use distinct keys for flags vs key/value metadata (e.g. `example` vs `examples`)","Audit inherited/base-type metadata before adding field-level metadata with the same key","Prefer KV attributes (which support multiple values) over flags when unsure"],"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"}