{"record":{"id":"63dbb88639f7cef2","repo":"vectordotdev/vector","slug":"component-cannot-have-multiple-names-defined","errorCode":null,"errorMessage":"component cannot have multiple names defined","messagePattern":"component cannot have multiple names defined","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/component_name.rs","lineNumber":82,"sourceCode":"            main_error.combine(error);\n        }\n\n        return main_error.into_compile_error().into();\n    }\n\n    // Any component names we have now have been validated, so we just need to check and make sure\n    // we actually have one, and only one, and spit out the correct errors otherwise.\n    if component_names.is_empty() {\n        return Error::new(\n            ident.span(),\n            \"component must have a name defined (e.g. `#[component_name(\\\"foobar\\\")]`)\",\n        )\n        .into_compile_error()\n        .into();\n    }\n\n    if component_names.len() > 1 {\n        return Error::new(ident.span(), \"component cannot have multiple names defined\")\n            .into_compile_error()\n            .into();\n    }\n\n    let component_name = component_names.remove(0);\n\n    // We have a single, valid component name, so let's actually spit out our derive.\n    let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();\n    let derived = quote! {\n        impl #impl_generics #ident #ty_generics #where_clause {\n            pub(super) const NAME: &'static str = #component_name;\n        }\n\n        impl #impl_generics ::vector_config::NamedComponent for #ident #ty_generics #where_clause {\n            fn get_component_name(&self) -> &'static str {\n                #component_name\n            }\n        }","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/component_name.rs#L64-L100","documentation":"After the component-name macro collects attribute names, it enforces exactly one: more than one `#[component_name(\"...\")]` on the same type produces the compile error \"component cannot have multiple names defined\" (all collected errors are also combined into one report). Multiple names would make the generated NAME constant ambiguous, so this is rejected at compile time rather than picking a winner.","triggerScenarios":"Placing two or more `#[component_name(\"a\")]` / `#[component_name(\"b\")]` attributes on one component config type, e.g. after renaming a component and leaving the old attribute behind.","commonSituations":"Renaming a component where the new attribute is added above the old one; merging code that brings in a duplicate attribute; macro copy-paste from another type.","solutions":["Delete all but one `#[component_name(...)]` attribute, keeping the intended final name.","Prefer renaming in the single existing attribute instead of adding a second one.","Run `cargo check -p <component-crate>` to confirm before continuing."],"exampleFix":"// before\n#[component_name(\"old_name\")]\n#[component_name(\"new_name\")]\n#[derive(ComponentName)]\nstruct Config;\n\n// after\n#[component_name(\"new_name\")]\n#[derive(ComponentName)]\nstruct Config;","handlingStrategy":"validation","validationCode":"// CI text guard: fail if a type has two component_name attributes\n// rg -U '#[component_name\\([^)]*\\)]\\s*\\n#\\[component_name' src/ && exit 1","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rename inside the single existing attribute instead of adding a second one.","After renaming a component, grep the file for the old name to remove leftovers."],"tags":["rust","proc-macro","compile-error","vector","component-metadata"],"backgroundTag":"duplicate-macro-attribute","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}