grafana/k6 · error
invalid tag, empty value
Error message
invalid tag, empty value
What it means
parseTagNameValue rejects --tag values with no '=' at all (idx == -1) or with '=' as the last character (idx == len-1): both mean the value side is empty. Every CLI tag must be a complete name=value pair; a bare name or a dangling 'name=' cannot form a metric tag.
Source
Thrown at internal/cmd/options.go:19
package cmd
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")View on GitHub (pinned to 93accf6570)
Solutions
- Write the full pair: --tag "env=prod"
- If tag values come from variables, default or validate them so the '=' always has a right-hand side
- Note that an intentionally empty value is not representable via this flag — choose a placeholder like 'unknown' if you need one
Example fix
# before k6 run --tag "env" script.js # ERR: invalid tag, empty value k6 run --tag "env=" script.js # ERR: invalid tag, empty value # after k6 run --tag "env=prod" script.js
Defensive patterns
Strategy: validation
Validate before calling
# every tag must be a full name=value pair
for t in "${TAGS[@]}"; do
case "$t" in
*=?*) ;; # name=value with non-empty value: OK
*) echo "invalid tag '$t': expected name=value" >&2; exit 1 ;;
esac
done Prevention
- Default empty tag values in scripts: : "${TAG_VALUE:=unknown}"
- Reject tags without '=' or ending in '=' in a shared pre-run lint
- Remember the CLI cannot express an intentionally empty tag value — use a placeholder
When it happens
Trigger: Running with --tag "env" (no '='), --tag "env=" (trailing '='), or the equivalent entries in K6_TAGS / repeated --tag flags where the value portion after the first '=' is empty.
Common situations: Forgetting the =value half when scripting --tag flags; a $TAG_VALUE variable that is empty so the shell produces "env="; assuming --tag works like a boolean flag; copying a tag list where the value was dropped.
Related errors
- invalid tag, empty name
- stack value is required but it was not passed or is empty
- 104
- the --local-execution flag is not compatible with the --exit
- the --local-execution flag is not compatible with the --show
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/9200ff44d5ace24a.
Report an issue: GitHub.