vectordotdev/vector · error

must exist

Error message

must exist

What it means

This panic occurs in vector-config-macros when generating a schema for an enum newtype (tuple) variant that has no fields at all. `variant.fields().first().expect("must exist")` assumes the variant classified as a newtype variant has exactly one positional field; a zero-field variant breaks that assumption. It is a derive-time panic surfaced as a compiler error in the user's crate, not a runtime failure.

Solutions

  1. Verify the failing enum variant is actually a newtype variant with exactly one unnamed field: `Variant(InnerType)`
  2. Fix the variant classification in generate_enum_variant_schema so unit variants (0 fields) are not routed to the newtype-variant schema generator
  3. In the macro, match on fields.len() == 1 explicitly and emit a compile_error! with the variant span instead of expect()

Example fix

// before
let field = variant.fields().first().expect("must exist");
// after
let field = variant.fields().first().ok_or_else(|| {
    syn::Error::new(variant.span(), "newtype enum variant must have exactly one field")
        .to_compile_error()
})?;
Defensive patterns

Strategy: validation

Validate before calling

// In the macro, before .first().expect():
assert_eq!(variant.fields().len(), 1, "newtype variant must have exactly one field");

Type guard

fn is_newtype_variant(v: &syn::Variant) -> bool {
    matches!(&v.fields, syn::Fields::Unnamed(f) if f.unnamed.len() == 1)
}

Prevention

When it happens

Trigger: Deriving `Configurable` on an enum containing a unit-style variant (zero fields) that the macro's classification logic mistakenly routes into `generate_enum_newtype_struct_variant_schema`, causing `.first()` to return None.

Common situations: Macro-internal misclassification after refactoring variant-shape detection; hand-edited or proc-macro-generated enums where the newtype path is invoked for a unit variant like `Foo` instead of `Foo(Inner)`.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at lib/vector-config-macros/src/configurable.rs:1012

                required,
                None
            );

            // If we have any flattened subschemas, deal with them now.
            if !flattened_subschemas.is_empty() {
                ::vector_config::schema::convert_to_flattened_schema(&mut schema, flattened_subschemas);
            }

            schema
        }
    }
}

fn generate_enum_newtype_struct_variant_schema(
    variant: &Variant<'_>,
    is_potentially_ambiguous: bool,
) -> proc_macro2::TokenStream {
    let field = variant.fields().first().expect("must exist");
    if field.required_one_of().is_some() {
        return syn::Error::new(
            field.span(),
            "`required_one_of` is not supported on enum variant fields",
        )
        .to_compile_error();
    }
    let field_schema = generate_struct_field(field, &[]);
    let maybe_fill_discriminant_map = is_potentially_ambiguous.then(|| {
        let variant_name = variant.ident().to_string();
        quote! {
            discriminant_map.insert(
                #variant_name,
                ::vector_config::schema::EnumDiscriminant::schema(subschema.clone()),
            );
        }
    });

View on GitHub (pinned to bdb87aeaa4)