vectordotdev/vector · error

argument must be a string

Error message

argument must be a string

What it means

remove_secret's runtime helper does key.as_str().expect("argument must be a string") (lib/vector-vrl/functions/src/remove_secret.rs). Like the other VRL built-ins, the key parameter is declared as BYTES and enforced by the VRL compiler at compile time, so the expect defends an internal invariant: a non-string Value reaching the helper means the type-checking contract was violated, not a user config problem.

Source

Thrown at lib/vector-vrl/functions/src/remove_secret.rs:5

use vector_vrl_category::Category;
use vrl::prelude::*;

fn remove_secret(ctx: &mut Context, key: Value) -> std::result::Result<Value, ExpressionError> {
    let key_str = key.as_str().expect("argument must be a string");
    ctx.target_mut().remove_secret(key_str.as_ref());
    Ok(Value::Null)
}

#[derive(Clone, Copy, Debug)]
pub struct RemoveSecret;

impl Function for RemoveSecret {
    fn identifier(&self) -> &'static str {
        "remove_secret"
    }

    fn usage(&self) -> &'static str {
        "Removes a secret from an event."
    }

    fn category(&self) -> &'static str {
        Category::Event.as_ref()

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Upgrade vector / vector-vrl crates together so the compiler's parameter kinds match the function implementation
  2. Pass compile-time-checked string arguments (literals or to_string!-coerced values) in VRL programs
  3. If embedding VRL directly, invoke functions only through the compiled program handle, never the raw helpers
  4. Report a reproducer to vectordot/vector if a stock build panics here

Example fix

# before (vrl)
remove_secret(secret_key)  # secret_key: any

# after (vrl)
remove_secret(to_string!(secret_key))
Defensive patterns

Strategy: type-guard

Validate before calling

# Ensure a bytes key at the call site
remove_secret(to_string!(key))

Type guard

fn is_bytes(v: &vrl::value::Value) -> bool {
    matches!(v, vrl::value::Value::Bytes(_))
}

Prevention

When it happens

Trigger: Reaching the helper with a Value that is not bytes/string — only possible via compiler bugs, mismatched vector-vrl crate versions in a custom build, or embedding code invoking the function outside the normal compile+run pipeline. Hand-written remove_secret(true) fails compilation with a type error long before this panic.

Common situations: Custom embeddings of VRL; version-mismatched crates after a partial dependency upgrade; nightly/regression builds of the VRL compiler losing a parameter kind.

Related errors


AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/b4fd440025952070. Report an issue: GitHub.