vectordotdev/vector · error

Tried to overwrite metadata flag

Error message

Tried to overwrite metadata flag '{key}' but already existed in schema metadata for `{type_name}` as a flag.

What it means

The mirror case of the flag clash: a key/value (array-capable) metadata attribute is being applied, but the key already exists in the schema's custom metadata map as a boolean flag. A flag cannot be converted into a multi-value array, so `apply_custom_attributes` panics to surface the inconsistent attribute combination instead of silently discarding data.

Solutions

  1. Rename one of the attributes so the keys don't collide
  2. Remove the duplicate attribute
  3. Use the same attribute kind (both KV or both flag) if the key must be shared

Example fix

// before
#[configurable(metadata(deprecated, example = "foo"))]
// after
#[configurable(metadata(deprecated, examples = "foo"))]
Defensive patterns

Strategy: validation

Validate before calling

fn no_flag_kv_collision(attrs: &[(&str, bool /* is_flag */)]) -> bool {
    let mut keys = std::collections::HashMap::new();
    attrs.iter().all(|(k, flag)| {
        keys.insert(k.to_string(), *flag).map_or(true, |prev| prev == *flag)
    })
}

Prevention

When it happens

Trigger: `apply_custom_attributes` processes a `CustomAttribute::KeyValue` whose key already maps to `Value::Bool` in the schema's custom metadata map (set by an earlier flag attribute), hitting the panic at lib/vector-config/src/schema/helpers.rs:132 while building the schema for `type_name`.

Common situations: Combining a flag attribute and a KV attribute with the same key (e.g. both named `example`) on one type/field; parent-type metadata colliding with field-level metadata of the same key name.

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


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

Appendix: source

Thrown at lib/vector-config/src/schema/helpers.rs:132

                    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.
                            _ => {
                                let taken_existing_value = std::mem::replace(existing_value, Value::Null);
                                *existing_value = Value::Array(vec![taken_existing_value, value.clone()]);
                            },
                        })
                        .or_insert(value.clone());
                }
            }
        }

        custom_map.len()
    };

View on GitHub (pinned to bdb87aeaa4)