{"record":{"id":"d948b0d93072d83b","repo":"vectordotdev/vector","slug":"field-should-be-named","errorCode":null,"errorMessage":"field should be named","messagePattern":"field should be named","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/vector-config-macros/src/configurable.rs","lineNumber":907,"sourceCode":"    let mut names = unflattened_serialized_names(fields);\n    if let Some(tag) = enclosing_tag {\n        names.push(tag.to_owned());\n    }\n    names\n}\n\nfn generate_named_enum_field(\n    field: &Field<'_>,\n    sibling_keys: &[String],\n) -> proc_macro2::TokenStream {\n    if field.required_one_of().is_some() {\n        return syn::Error::new(\n            field.span(),\n            \"`required_one_of` is not supported on enum variant fields\",\n        )\n        .to_compile_error();\n    }\n    let field_name = field.ident().expect(\"field should be named\");\n    let field_ty = field.ty();\n    let field_already_contained = format!(\n        \"schema properties already contained entry for `{field_name}`, this should not occur\"\n    );\n    let field_key = field.name().to_string();\n\n    let field_schema = generate_struct_field(field, sibling_keys);\n\n    // Fields that have no default value are inherently required.  Unlike fields on a normal\n    // struct, we can't derive a default value for an individual field because `serde`\n    // doesn't allow even specifying a default value for an enum overall, only structs.\n    let spanned_is_optional = quote_spanned! {field.span()=>\n        <#field_ty as ::vector_config::Configurable>::is_optional()\n    };\n    let maybe_field_required = if field.default_value().is_none() {\n        Some(quote! {\n        if !#spanned_is_optional {\n                if !required.insert(#field_key.to_string()) {","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/lib/vector-config-macros/src/configurable.rs#L889-L925","documentation":"This panic fires in vector-config-macros when generating a JSON schema for a named-field enum variant whose field unexpectedly has no identifier (i.e. a positional/tuple field reached the named-variant code path). The macro calls `field.ident().expect(\"field should be named\")` because by that point the variant has been classified as a struct-style (named) variant, so every field must have a name. It is a derive-time internal invariant panic, not a runtime error in user code.","triggerScenarios":"Deriving `Configurable` on an enum whose variant is dispatched to `generate_enum_struct_named_variant_schema` while a field carries no identifier — e.g. an inconsistency in the syn-derived `Variant` data or a macro-internal bug in variant classification (a tuple/newtype-style field routed into the named-field generator).","commonSituations":"Contributing to the vector-config derive macros and accidentally routing tuple-variant fields through the named-variant path; changing variant-shape detection logic and breaking the invariant that struct variants only contain named fields.","solutions":["Check the enum variant that fails to derive: it must be a true named-field variant (`Variant { field: Type }`) for this code path","Inspect generate_enum_variant_schema's variant classification so tuple/newtype fields go to generate_enum_newtype_struct_variant_schema instead","If it is a macro bug, add an explicit shape check before calling field.ident() and emit a syn::Error with a span instead of expect()"],"exampleFix":"// before\nlet field_name = field.ident().expect(\"field should be named\");\n// after\nlet field_name = field.ident().ok_or_else(|| {\n    syn::Error::new(field.span(), \"expected a named field on an enum struct variant\")\n        .to_compile_error()\n})?;","handlingStrategy":"validation","validationCode":"// In the macro, before calling ident():\nif field.ident().is_none() {\n    return syn::Error::new(field.span(), \"expected named field on struct variant\").to_compile_error();\n}","typeGuard":"fn is_named_field(f: &syn::Field) -> bool { f.ident.is_some() }","tryCatchPattern":null,"preventionTips":["Keep variant classification (named vs tuple vs unit) centralized in one match in generate_enum_variant_schema","Emit syn::Error with spans instead of expect() in proc-macro code paths","Add macro unit tests covering all enum variant shapes"],"tags":["rust","proc-macro","derive-macro","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"}