grafana/k6 · error
invalid tag, empty string
Error message
invalid tag, empty string
What it means
The earliest sentinel in parseTagNameValue: the whole --tag argument is the empty string, before any '='-splitting is attempted. k6 cannot derive a name or value from an empty tag, so option parsing aborts with "error parsing tag ''". Distinct from empty-name (tag starts with '=') and empty-value (no '=' or trailing '=').
Source
Thrown at internal/cmd/options.go:20
import (
"errors"
"fmt"
"strings"
"github.com/spf13/pflag"
"gopkg.in/guregu/null.v3"
"go.k6.io/k6/v2/internal/build"
"go.k6.io/k6/v2/lib"
"go.k6.io/k6/v2/lib/types"
"go.k6.io/k6/v2/metrics"
)
var (
errTagEmptyName = errors.New("invalid tag, empty name")
errTagEmptyValue = errors.New("invalid tag, empty value")
errTagEmptyString = errors.New("invalid tag, empty string")
)
func optionFlagSet() *pflag.FlagSet {
flags := pflag.NewFlagSet("", 0)
flags.SortFlags = false
flags.Int64P("vus", "u", 1, "number of virtual users")
flags.DurationP("duration", "d", 0, "test duration limit")
flags.Int64P("iterations", "i", 0, "script total iteration limit (among all VUs)")
flags.StringSliceP("stage", "s", nil, "add a `stage`, as `[duration]:[target]`")
flags.String("execution-segment", "", "limit execution to the specified segment, e.g. 10%, 1/3, 0.2:2/3")
flags.String("execution-segment-sequence", "", "the execution segment sequence") // TODO better description
flags.BoolP("paused", "p", false, "start the test in a paused state")
flags.Bool("no-setup", false, "don't run setup()")
flags.Bool("no-teardown", false, "don't run teardown()")
flags.Int64("max-redirects", 10, "follow at most n redirects")
flags.Int64("batch", 20, "max parallel batch reqs")
flags.Int64("batch-per-host", 6, "max parallel batch reqs per host")View on GitHub (pinned to 01ffac6f24)
Solutions
- Remove the empty --tag argument or give it real content: --tag name=value
- Build the flag conditionally: only append --tag "$TAG" when TAG is non-empty
- Print the assembled command before executing to spot empty flag values
Example fix
# before
TAG=""
k6 run --tag "$TAG" script.js # expands to --tag "" -> invalid tag, empty string
# after
TAG="${TAG:-}"
if [ -n "$TAG" ]; then k6 run --tag "$TAG" script.js; else k6 run script.js; fi Defensive patterns
Strategy: validation
Validate before calling
# build args conditionally so empty tag vars never reach k6
ARGS=()
[ -n "$TAG" ] && ARGS+=(--tag "$TAG")
k6 run "${ARGS[@]}" script.js Type guard
function isValidTag(s) {
const i = s.indexOf('=');
return i > 0 && i < s.length - 1;
} Prevention
- Never interpolate possibly-empty variables directly into --tag "$VAR"
- Append --tag flags only when the value is non-empty (shell: [ -n "$VAR" ] && ...)
- Echo the final command in CI logs so empty flag values are visible before k6 parses them
When it happens
Trigger: Passing `--tag ""` explicitly, or far more often `--tag "$TAG"` where the TAG environment variable is unset or empty so the shell expands to an empty string; can also come from argument arrays built programmatically that append an empty element.
Common situations: CI pipelines conditionally adding tags where the condition produced an empty string; optional-tag logic that appends the flag unconditionally; typo'd env var names yielding empty expansion.
Related errors
- invalid tag, empty name
- invalid tag, empty value
- stack URL is required to validate token
- There were problems with the specified script configuration:
- empty name provided to SharedArray's constructor
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/df68930f4aec5b21.
Report an issue: GitHub.