vectordotdev/vector · error
Tried to set metadata flag
Error message
Tried to set metadata flag '{key}' but already existed in schema metadata for `{type_name}`. What it means
When applying custom metadata attributes to a schema, boolean flag attributes (e.g. `#[configurable(metadata(...))]` style flags) are written into the schema's `custom` metadata map. If the key already holds a non-boolean, non-null value — meaning a different metadata attribute already claimed that key — the two attributes clash and the code panics rather than silently overwriting unrelated metadata.
Solutions
- Rename one of the conflicting metadata keys so each attribute has a unique key
- Remove the redundant/duplicate metadata attribute
- Use matching value kinds (both flags) if the same key is intentionally set twice
Example fix
// before #[configurable(metadata(example = "x", example = true))] // after #[configurable(metadata(example = "x", deprecated = true))]
Defensive patterns
Strategy: validation
Validate before calling
fn flags_unique(attrs: &[(String, String)]) -> bool {
let mut seen = std::collections::HashSet::new();
attrs.iter().all(|(k, _)| seen.insert(k.clone()))
}
// assert!(flags_unique(&metadata_attrs), "duplicate metadata keys with differing kinds"); Prevention
- Keep metadata key names unique per type/field
- Don't mix flag and KV attributes under the same key name
- Review metadata attributes when copying definitions between types
When it happens
Trigger: `apply_custom_attributes` (called from `apply_configurable_metadata`) processes a `CustomAttribute::Flag` whose key already exists in the schema's custom metadata map with a non-`Value::Bool` value (e.g. an array or string from a KV attribute), triggering the panic at lib/vector-config/src/schema/helpers.rs:121.
Common situations: Two different `#[configurable(metadata(...))]` attributes on the same type or field using the same key with different value kinds; a base type's metadata clashing with field-level metadata overrides.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- Tried to overwrite metadata flag
- No description provided for
- #tag_already_contained
- 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/017515891bb7ca48.
Report an issue: GitHub.
Appendix: source
Thrown at lib/vector-config/src/schema/helpers.rs:121
if let Some(message) = metadata.deprecated_message() {
custom_map.insert(
"deprecated_message".to_string(),
serde_json::Value::String(message.to_string()),
);
}
for attribute in metadata.custom_attributes() {
match attribute {
CustomAttribute::Flag(key) => {
match custom_map.insert(key.to_string(), Value::Bool(true)) {
// Overriding a flag is fine, because flags are only ever "enabled", so there's
// no harm to enabling it... again. Likewise, if there was no existing value,
// it's fine.
Some(Value::Bool(_)) | None => {}
// Any other value being present means we're clashing with a different metadata
// attribute, which is not good, so we have to bail out.
_ => panic!(
"Tried to set metadata flag '{key}' but already existed in schema metadata for `{type_name}`."
),
}
}
CustomAttribute::KeyValue { key, value } => {
custom_map.entry(key.to_string())
.and_modify(|existing_value| match existing_value {
// We already have a flag entry for this key, which we cannot turn into an
// array, so we panic in this particular case to signify the weirdness.
Value::Bool(_) => {
panic!("Tried to overwrite metadata flag '{key}' but already existed in schema metadata for `{type_name}` as a flag.");
},
// The entry is already a multi-value KV pair, so just append the value.
Value::Array(items) => {
items.push(value.clone());
},
// The entry is not already a multi-value KV pair, so turn it into one.
_ => {View on GitHub (pinned to bdb87aeaa4)