{"record":{"id":"df68930f4aec5b21","repo":"grafana/k6","slug":"invalid-tag-empty-string","errorCode":null,"errorMessage":"invalid tag, empty string","messagePattern":"invalid tag, empty string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/options.go","lineNumber":20,"sourceCode":"\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\")\n\tflags.Int64(\"batch\", 20, \"max parallel batch reqs\")\n\tflags.Int64(\"batch-per-host\", 6, \"max parallel batch reqs per host\")","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/cmd/options.go#L2-L38","documentation":"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 '=').","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nTAG=\"\"\nk6 run --tag \"$TAG\" script.js    # expands to --tag \"\" -> invalid tag, empty string\n\n# after\nTAG=\"${TAG:-}\"\nif [ -n \"$TAG\" ]; then k6 run --tag \"$TAG\" script.js; else k6 run script.js; fi","handlingStrategy":"validation","validationCode":"# build args conditionally so empty tag vars never reach k6\nARGS=()\n[ -n \"$TAG\" ] && ARGS+=(--tag \"$TAG\")\nk6 run \"${ARGS[@]}\" script.js","typeGuard":"function isValidTag(s) {\n  const i = s.indexOf('=');\n  return i > 0 && i < s.length - 1;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["k6","cli-flags","tag","validation","shell-quoting"],"backgroundTag":"malformed-flag-value","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}