{"record":{"id":"e2ce076aa3962342","repo":"vectordotdev/vector","slug":"component-must-have-a-name-defined-e-g-compon","errorCode":null,"errorMessage":"component must have a name defined (e.g. `#[component_name(\"foobar\")]`)","messagePattern":"component must have a name defined \\(e\\.g\\. `#\\[component_name\\(\"foobar\"\\)\\]`\\)","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/component_name.rs","lineNumber":73,"sourceCode":"                errors.push(e);\n                None\n            }\n        })\n        .collect::<Vec<_>>();\n\n    if !errors.is_empty() {\n        let mut main_error = errors.remove(0);\n        for error in errors.drain(..) {\n            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! {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/vectordotdev/vector/blob/3708c39b12a93212ed8b8d7510b4cc7769cb5864/lib/vector-config-macros/src/component_name.rs#L55-L91","documentation":"The component-name derive/attribute machinery in vector-config-macros requires every instrumented component type to declare exactly one name via `#[component_name(\"...\")]`. After validating any attribute tokens, if none produced a usable name, the macro emits this compile error on the type's span. Without the constant NAME the generated docs and config schema cannot identify the component.","triggerScenarios":"Applying the component-name derive (or the `#[configurable_component(...)]` family) to a type without attaching `#[component_name(\"my_component\")]`, or with the attribute misspelled so it is not recognized.","commonSituations":"Contributors adding a new source/transform/sink who copy the derive list but drop the name attribute; typos like `#[component_names(...)]` or placing the attribute on the wrong item so it is not collected.","solutions":["Add exactly one `#[component_name(\"your_component\")]` attribute to the type carrying the derive.","Check spelling/placement — the attribute must sit on the same item the macro processes.","Copy the attribute block from a sibling component in the same directory as a template."],"exampleFix":"// before\n#[derive(ComponentName)]\nstruct MySinkConfig;\n\n// after\n#[component_name(\"my_sink\")]\n#[derive(ComponentName)]\nstruct MySinkConfig;","handlingStrategy":"validation","validationCode":"// The compiler enforces this at derive time; fix by adding the attribute:\n// #[component_name(\"my_component\")]\n// #[derive(...)] struct MyConfig;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding a component, copy the full attribute set from a sibling component first, then rename.","Keep the derive and its component_name attribute adjacent so they are edited together."],"tags":["rust","proc-macro","compile-error","vector","component-metadata"],"backgroundTag":"missing-macro-attribute","analyzedSha":"3708c39b12a93212ed8b8d7510b4cc7769cb5864","analyzedAt":"2026-08-20T07:02:18.786Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}