vectordotdev/vector · error · syn::Error
component cannot have multiple names defined
Error message
component cannot have multiple names defined
What it means
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.
Source
Thrown at lib/vector-config-macros/src/component_name.rs:82
main_error.combine(error);
}
return main_error.into_compile_error().into();
}
// Any component names we have now have been validated, so we just need to check and make sure
// we actually have one, and only one, and spit out the correct errors otherwise.
if component_names.is_empty() {
return Error::new(
ident.span(),
"component must have a name defined (e.g. `#[component_name(\"foobar\")]`)",
)
.into_compile_error()
.into();
}
if component_names.len() > 1 {
return Error::new(ident.span(), "component cannot have multiple names defined")
.into_compile_error()
.into();
}
let component_name = component_names.remove(0);
// We have a single, valid component name, so let's actually spit out our derive.
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let derived = quote! {
impl #impl_generics #ident #ty_generics #where_clause {
pub(super) const NAME: &'static str = #component_name;
}
impl #impl_generics ::vector_config::NamedComponent for #ident #ty_generics #where_clause {
fn get_component_name(&self) -> &'static str {
#component_name
}
}View on GitHub (pinned to 3708c39b12)
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.
Example fix
// before
#[component_name("old_name")]
#[component_name("new_name")]
#[derive(ComponentName)]
struct Config;
// after
#[component_name("new_name")]
#[derive(ComponentName)]
struct Config; Defensive patterns
Strategy: validation
Validate before calling
// CI text guard: fail if a type has two component_name attributes // rg -U '#[component_name\([^)]*\)]\s*\n#\[component_name' src/ && exit 1
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- component must have a name defined (e.g. `#[component_name("
- {component_type}s must have a name specified (e.g. `{compone
- #[derive(NamedInternalEvent)] can only be used with structs
- expected a string literal for the {component_type} name (i.e
- component name must be non-empty
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/63dbb88639f7cef2.
Report an issue: GitHub.