vectordotdev/vector · error · syn::Error
`required_one_of` requires the field to be optional; use…
Error message
`required_one_of` requires the field to be optional; use `Option<T>` or add `#[serde(default)]`
What it means
A `required_one_of` field must be able to be absent without failing ordinary deserialization; otherwise the group logic would always error even when another field in the group was provided. The derive therefore requires the field to be `Option<T>`, or to have a field-level or container-level `#[serde(default)]`, and emits this compile error otherwise.
Solutions
- Change the field type to `Option<T>`
- Or add `#[serde(default)]` to the field (requires `T: Default`)
- Or add `#[serde(default)]` at the container level if all fields default
- Use plain required-field semantics (no attribute) if the field must always be present
Example fix
// before
#[configurable_component]
struct Config {
#[required_one_of]
endpoint: String,
#[required_one_of]
socket: String,
}
// after
#[configurable_component]
struct Config {
#[required_one_of]
endpoint: Option<String>,
#[required_one_of]
socket: Option<String>,
} Defensive patterns
Strategy: validation
Validate before calling
// a required_one_of field must be Option<T> or have a serde default
fn ok_for_required_one_of<T: Default>(f: &Field) -> bool {
is_option_type(&f.ty) || f.default_value().is_some()
} Prevention
- Make every required_one_of field Option<T> by convention
- Add #[serde(default)] at field or container level when defaults exist
- Remember required_one_of means 'at least one of', not 'required'
When it happens
Trigger: Marking a non-Option field `#[required_one_of]` with no `#[serde(default)]` on the field and no `#[serde(default)]` on the container, then compiling a struct using the configurable derive.
Common situations: Adding `required_one_of` to a required `String`/`u64` field thinking it means 'required' rather than 'at least one of'; copying the attribute onto an existing mandatory field during a config refactor.
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
- `required_one_of` cannot be applied to a…
- `required_one_of` cannot be applied to a `#[serde(skip)]`…
- `required_one_of` cannot be applied to a…
- component cannot have multiple names defined
- component must have a name defined (e.g…
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/a7bfd026454c5bca.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-config-macros/src/configurable.rs:427
if !field.visible() {
return syn::Error::new(
field.span(),
"`required_one_of` cannot be applied to a `#[serde(skip)]` field",
)
.to_compile_error();
}
if field.flatten() {
return syn::Error::new(
field.span(),
"`required_one_of` cannot be applied to a `#[serde(flatten)]` field",
)
.to_compile_error();
}
if !is_option_type(field.ty())
&& field.default_value().is_none()
&& container.default_value().is_none()
{
return syn::Error::new(
field.span(),
"`required_one_of` requires the field to be optional; use `Option<T>` or add `#[serde(default)]`",
)
.to_compile_error();
}
if field.skip_deserializing() {
return syn::Error::new(
field.span(),
"`required_one_of` cannot be applied to a `#[serde(skip_deserializing)]` field; users cannot set its value",
)
.to_compile_error();
}
}
}
// Collect required_one_of groups at macro-expansion time: group_name -> [serde field names].
let mut groups: std::collections::BTreeMap<String, Vec<String>> =
std::collections::BTreeMap::new();View on GitHub (pinned to bdb87aeaa4)