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
- Verify the failing enum variant is actually a newtype variant with exactly one unnamed field: `Variant(InnerType)`
- Fix the variant classification in generate_enum_variant_schema so unit variants (0 fields) are not routed to the newtype-variant schema generator
- 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
- Verify the failing variant is written as `Name(T)` with one positional field
- Route unit variants through their own schema generator
- Prefer ok_or_else with syn::Error over expect in derive code
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
- field should be named
- #[derive(NamedInternalEvent)] can only be used with structs
- a record with a next ID must have an event count
- a valid HTTP/1 URI is valid as an HTTP URI
- a validated HTTP endpoint is a valid `http 1` URI
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)