vectordotdev/vector · error

has no component identifier

Error message

{description} has no component identifier

What it means

`mapping_key` extracts the single string key identifying the component within a `sources`/`transforms`/`sinks` mapping. If the mapping has no string keys (empty mapping, or keys that are numbers/booleans/null), it cannot determine the component identifier and throws this error.

Solutions

  1. Add exactly one string-keyed entry to the component section naming the component.
  2. Quote numeric-looking keys (e.g. `"my_source":`) so they parse as strings.
  3. Resolve leftover merge-conflict or empty-section placeholders before running the check.

Example fix

// before
sources:
  2024_config:
    type: file

// after
sources:
  my_source:
    type: file
Defensive patterns

Strategy: validation

Validate before calling

const stringKeys = Object.keys(mapping).filter(k => typeof k === 'string');
if (stringKeys.length < 1) {
  throw new Error(`${description} must contain at least one string component key`);
}

Type guard

function hasStringKey(mapping) {
  return Object.keys(mapping ?? {}).some(k => typeof k === 'string' && k.length > 0);
}

Prevention

When it happens

Trigger: The component section mapping contains no entries, or its keys are non-string YAML scalars (e.g. unquoted numeric keys like `2024:`), which `YamlValue::as_str` rejects.

Common situations: An example file with an empty placeholder section was committed; YAML parsed an unquoted numeric key as an integer; merge conflicts left an empty mapping behind.

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


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

Appendix: source

Thrown at vdev/src/commands/check/component_examples.rs:393

}

fn yaml_mapping(value: &YamlValue, description: &str) -> Result<Mapping> {
    value
        .as_mapping()
        .cloned()
        .ok_or_else(|| anyhow!("Expected {description} to be a YAML mapping"))
}

fn mapping_value<'a>(mapping: &'a Mapping, key: &str) -> Option<&'a YamlValue> {
    mapping.get(YamlValue::String(key.to_owned()))
}

fn mapping_key(mapping: &Mapping, description: &str) -> Result<String> {
    mapping
        .keys()
        .find_map(YamlValue::as_str)
        .map(str::to_owned)
        .ok_or_else(|| anyhow!("{description} has no component identifier"))
}

fn vector_binary(repo_root: &Path) -> Result<PathBuf> {
    if let Some(vector_bin) = std::env::var_os("VECTOR_BIN") {
        return Ok(PathBuf::from(vector_bin));
    }

    let status = Command::new("cargo")
        .current_dir(repo_root)
        .args(["build", "--bin", "vector"])
        .status()
        .context("Failed to build Vector for example validation")?;
    if !status.success() {
        bail!("Failed to build Vector for example validation")
    }

    let target_dir = std::env::var_os("CARGO_TARGET_DIR").map_or_else(
        || repo_root.join("target"),

View on GitHub (pinned to bdb87aeaa4)