vectordotdev/vector · error
argument must be a string
Error message
argument must be a string
What it means
find_vector_metrics' helper unwraps its key with key.as_str().expect("argument must be a string") (lib/vector-vrl/metrics/src/find_vector_metrics.rs). The key parameter is declared required BYTES in the function's parameter list, and the VRL compiler type-checks call sites, so this panic indicates the runtime value violated a compile-time guarantee (internal invariant) rather than a user scripting mistake.
Source
Thrown at lib/vector-vrl/metrics/src/find_vector_metrics.rs:16
use std::{collections::BTreeMap, sync::LazyLock};
use vector_vrl_category::Category;
use vrl::prelude::expression::Expr;
use vrl::prelude::*;
use crate::common::{
metric_into_vrl, metrics_vrl_typedef, resolve_tags, validate_tags, Error, MetricsStorage,
};
fn find_metrics(
metrics_storage: &MetricsStorage,
key: Value,
tags: BTreeMap<String, String>,
) -> Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
Ok(Value::Array(
metrics_storage
.find_metrics(&key_str, tags)
.iter()
.map(metric_into_vrl)
.collect(),
))
}
static DEFAULT_TAGS: LazyLock<Value> = LazyLock::new(|| Value::Object(BTreeMap::new()));
static PARAMETERS: LazyLock<Vec<Parameter>> = LazyLock::new(|| {
vec![
Parameter::required("key", kind::BYTES, "The metric name to search."),
Parameter::optional(
"tags",
kind::OBJECT,
"Tags to filter the results on. Values in this object support wildcards ('*') to match on parts of the tag value.",View on GitHub (pinned to 3708c39b12)
Solutions
- Align vector-vrl crates to a single Vector release
- Use string literals or to_string! for the key in VRL programs
- Invoke functions only through compiled programs in embedding code
- Report compiler-invariant breaks with a minimal VRL program upstream
Example fix
# before (vrl) find_vector_metrics(key) # key: any # after (vrl) find_vector_metrics(to_string!(key))
Defensive patterns
Strategy: type-guard
Validate before calling
# Statically-typed key argument find_vector_metrics(to_string!(key))
Type guard
fn is_bytes(v: &vrl::value::Value) -> bool {
matches!(v, vrl::value::Value::Bytes(_))
} Prevention
- Use string literals for metric name filters
- vector vrl check the program during development
- Align vector-vrl-metrics and compiler crate versions
When it happens
Trigger: The compiled function executing with a non-bytes key Value — normally impossible because find_vector_metrics(42) is rejected during VRL compilation; triggered by compiler regressions, mixed vector-vrl crate versions, or code invoking the helper directly (unit tests, embeddings).
Common situations: VRL compiler development and fuzzing; custom builds with partially upgraded vector-vrl-* crates; direct helper calls in internal tests.
Related errors
- argument must be a string
- argument must be a string
- argument must be a string
- argument must be a string
- key must be a string
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/25625d99c3e03eb4.
Report an issue: GitHub.