{"record":{"id":"5b9227f78e935f76","repo":"grafana/k6","slug":"invalid-tag-empty-name","errorCode":null,"errorMessage":"invalid tag, empty name","messagePattern":"invalid tag, empty name","errorType":"validation","errorClass":"errTagEmptyName","httpStatus":null,"severity":"error","filePath":"internal/cmd/options.go","lineNumber":18,"sourceCode":"package cmd\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"strings\"\n\n\t\"github.com/spf13/pflag\"\n\t\"gopkg.in/guregu/null.v3\"\n\n\t\"go.k6.io/k6/v2/internal/build\"\n\t\"go.k6.io/k6/v2/lib\"\n\t\"go.k6.io/k6/v2/lib/types\"\n\t\"go.k6.io/k6/v2/metrics\"\n)\n\nvar (\n\terrTagEmptyName   = errors.New(\"invalid tag, empty name\")\n\terrTagEmptyValue  = errors.New(\"invalid tag, empty value\")\n\terrTagEmptyString = errors.New(\"invalid tag, empty string\")\n)\n\nfunc optionFlagSet() *pflag.FlagSet {\n\tflags := pflag.NewFlagSet(\"\", 0)\n\tflags.SortFlags = false\n\n\tflags.Int64P(\"vus\", \"u\", 1, \"number of virtual users\")\n\tflags.DurationP(\"duration\", \"d\", 0, \"test duration limit\")\n\tflags.Int64P(\"iterations\", \"i\", 0, \"script total iteration limit (among all VUs)\")\n\tflags.StringSliceP(\"stage\", \"s\", nil, \"add a `stage`, as `[duration]:[target]`\")\n\tflags.String(\"execution-segment\", \"\", \"limit execution to the specified segment, e.g. 10%, 1/3, 0.2:2/3\")\n\tflags.String(\"execution-segment-sequence\", \"\", \"the execution segment sequence\") // TODO better description\n\tflags.BoolP(\"paused\", \"p\", false, \"start the test in a paused state\")\n\tflags.Bool(\"no-setup\", false, \"don't run setup()\")\n\tflags.Bool(\"no-teardown\", false, \"don't run teardown()\")\n\tflags.Int64(\"max-redirects\", 10, \"follow at most n redirects\")","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/options.go#L1-L36","documentation":"parseTagNameValue rejects --tag values whose '=' is the first character (idx == 0), i.e. the tag name is empty. CLI tag arguments must be name=value pairs; an empty name has nothing to attach the metric tag to, so option parsing fails before the test starts.","triggerScenarios":"Running with --tag \"=somevalue\" (or K6_TAGS=\"=somevalue\" / --tag \"=a=b\" variants where the name portion before the first '=' is empty). The switch on the index of '=' hits case 0 and returns this error.","commonSituations":"Shell variable meant to hold the tag name being empty and interpolated as \"$NAME=value\" -> \"=value\"; scripts concatenating tag parts without validating the name; copy-paste from docs dropping the name.","solutions":["Give the tag a name: use --tag \"env=prod\" syntax (name=value)","If the tag comes from variables, assert the name part is non-empty before building the argument","Check K6_TAGS entries too — each entry must contain a non-empty name before the '='"],"exampleFix":"# before\nk6 run --tag \"=prod\" script.js   # ERR: invalid tag, empty name\n\n# after\nk6 run --tag \"env=prod\" script.js","handlingStrategy":"validation","validationCode":"# validate every tag argument before invoking k6\nfor t in \"${TAGS[@]}\"; do\n  case \"$t\" in\n    \"\"|\"=\"*|\"\"*[=]*) ;;\n  esac\ndone\n# simpler guard: name=${t%%=*}; [ -n \"$name\" ] || { echo \"bad tag: $t\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build tag arguments as \"key=value\" pairs from validated variables","Assert the name part (${t%%=*}) is non-empty in wrappers before passing --tag","Same rule applies to K6_TAGS entries — lint them once in a shared script"],"tags":["cli","tags","flags","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}