{"record":{"id":"0aea08ddee58d830","repo":"vectordotdev/vector","slug":"tag-already-contained","errorCode":null,"errorMessage":"#tag_already_contained","messagePattern":"#tag_already_contained","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":1129,"sourceCode":"        // { \"field_using_enum\": { \"<tag>\": \"VariantName\", \"some_field\": false } }\n        //\n        // # Struct form with unnamed field is not valid here.  See comments below.\n        //\n        // # Unit form.\n        // { \"field_using_enum\": { \"<tag>\": \"VariantName\" } }\n        Tagging::Internal { tag } => match variant.style() {\n            Style::Struct => {\n                let tag_already_contained = format!(\n                    \"enum tag `{tag}` already contained as a field in variant; tag cannot overlap with any fields in any variant\"\n                );\n\n                // Just generate the tag field directly and pass it along to be included in the\n                // struct schema.\n                let tag_schema = generate_enum_variant_tag_schema(variant);\n                let tag_field = quote! {\n                    {\n                        if let Some(_) = properties.insert(#tag.to_string(), #tag_schema) {\n                            panic!(#tag_already_contained);\n                        }\n\n                        if !required.insert(#tag.to_string()) {\n                            panic!(#tag_already_contained);\n                        }\n                    }\n                };\n                generate_enum_struct_named_variant_schema(\n                    variant,\n                    Some(tag_field),\n                    Some(tag),\n                    false,\n                )\n            }\n            Style::Tuple => panic!(\"tuple variants should be rejected during AST parsing\"),\n            Style::Newtype => {\n                // We have to delegate viability to `serde`, essentially, because using internal tagging for a newtype\n                // variant is only possible when the inner field is a struct or map, and we can't access that type of","sourceCodeStart":1111,"sourceCodeEnd":1147,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config-macros/src/configurable.rs#L1111-L1147","documentation":"This is a compile-time panic emitted by the generated schema-building code of the `Configurable` derive macro. When generating the schema for an adjacently-tagged (or similarly tagged) enum variant, the macro inserts a synthetic `tag` property into the variant's `properties` and `required` sets. If the variant's own fields already contain a property with the same name as the tag key, the insertion collides and the macro panics, because the generated JSON Schema would be self-contradictory (two definitions for one property name).","triggerScenarios":"Deriving `Configurable` on an enum annotated with an adjacent/internal tag (e.g. `#[configurable(tag = \"type\")]`) where one of the variant structs already declares a field whose name equals the tag key (`type`), so `properties.insert(tag)` returns `Some` or `required.insert` returns `false` during `generate_enum_variant_schema`.","commonSituations":"Adding a new enum variant whose struct reuses the tag field name; renaming a tag attribute to collide with an existing variant field; copying a variant definition from another enum that uses a different tag name.","solutions":["Rename the conflicting field inside the variant struct so it no longer matches the tag key","Change the enum-level tag name via the tag attribute to something that does not collide with any variant field","Prefix or restructure the variant's fields so the tag property is generated only by the macro"],"exampleFix":"// before\n#[configurable(tag = \"type\")]\nenum Source {\n  A { type: String, port: u16 },\n}\n// after\n#[configurable(tag = \"type\")]\nenum Source {\n  A { kind: String, port: u16 },\n}","handlingStrategy":"validation","validationCode":"// Before deriving Configurable on a tagged enum, check variant fields against the tag:\nfn tag_conflicts<'a>(tag: &str, variant_fields: impl IntoIterator<Item = &'a str>) -> bool {\n    variant_fields.into_iter().any(|f| f == tag)\n}\n// assert!(!tag_conflicts(\"type\", [\"type\", \"port\"]), \"field collides with tag key\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the tag key name (e.g. \"type\", \"kind\") reserved — never use it as a field name in variant structs","Grep the enum's variants for the tag name after changing any tag attribute","Standardize tag keys per crate to reduce collision chance"],"tags":["rust","proc-macro","json-schema","compile-time-panic"],"backgroundTag":"internal-invariant-violation","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"}