vectordotdev/vector · error · syn::Error

component must have a name defined (e.g…

Error message

component must have a name defined (e.g. `#[component_name("foobar")]`)

What it means

The `ComponentName` derive in vector-config-macros collects component names from helper attributes like `#[component_name("...")]` and requires exactly one. This compile error fires when none was found, meaning Vector cannot assign the component its registry/config name. It is the 'zero names' case of the derive's own validation.

Solutions

  1. Add a single `#[component_name("my_component")]` attribute to the struct
  2. Check that the attribute is not inside a disabled `#[cfg(...)]` block
  3. Ensure the attribute path matches the crate's expected helper attribute name exactly (no typo)

Example fix

// before
#[derive(ComponentName)]
struct MySinkConfig;
// after
#[derive(ComponentName)]
#[component_name("my_sink")]
struct MySinkConfig;
Defensive patterns

Strategy: validation

Validate before calling

// ensure exactly one #[component_name("...")] helper exists before building
grep -c '#\[component_name(' src/**/my_component.rs # must print 1

Prevention

When it happens

Trigger: Deriving `ComponentName` (or `#[configurable_component]`-style macros that invoke it) on a struct without any `#[component_name("...")]` helper attribute, or with all helper attributes stripped (e.g. behind a `#[cfg]` that is disabled).

Common situations: Adding the derive but forgetting the helper attribute; deleting the attribute during refactoring; attribute gated out by a feature flag so the count is zero on some builds.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16). Data as JSON: /api/errors/e2ce076aa3962342. Report an issue: GitHub.

Appendix: source

Thrown at lib/vector-config-macros/src/component_name.rs:73

                errors.push(e);
                None
            }
        })
        .collect::<Vec<_>>();

    if !errors.is_empty() {
        let mut main_error = errors.remove(0);
        for error in errors.drain(..) {
            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! {

View on GitHub (pinned to bdb87aeaa4)