{"record":{"id":"4b35cc7c32026f2d","repo":"grafana/k6","slug":"stack-value-is-required-but-it-was-not-passed-or-i","errorCode":null,"errorMessage":"stack value is required but it was not passed or is empty","messagePattern":"stack value is required but it was not passed or is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud_login.go","lineNumber":107,"sourceCode":"\n\tshow := getNullBool(cmd.Flags(), \"show\")\n\treset := getNullBool(cmd.Flags(), \"reset\")\n\ttokenInput := getNullString(cmd.Flags(), \"token\")\n\tstackInput := getNullString(cmd.Flags(), \"stack\")\n\n\tswitch {\n\tcase reset.Valid:\n\t\tnewCloudConf.Token = null.StringFromPtr(nil)\n\t\tnewCloudConf.StackID = null.IntFromPtr(nil)\n\t\tnewCloudConf.StackURL = null.StringFromPtr(nil)\n\t\tnewCloudConf.DefaultProjectID = null.IntFromPtr(nil)\n\t\tprintToStdout(c.globalState, \"\\nToken and stack info have been reset.\\n\")\n\tcase show.Bool:\n\t\tprintConfig(c.globalState, newCloudConf)\n\t\treturn nil\n\tcase tokenInput.Valid || stackInput.Valid:\n\t\tif !stackInput.Valid || stackInput.String == \"\" {\n\t\t\treturn errors.New(\"stack value is required but it was not passed or is empty\")\n\t\t}\n\t\tif !tokenInput.Valid || tokenInput.String == \"\" {\n\t\t\treturn errors.New(\"token value is required but it was not passed or is empty\")\n\t\t}\n\t\terr := authenticateUserToken(c.globalState, &newCloudConf, currentJSONConfigRaw, tokenInput.String, stackInput.String)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\tdefault:\n\t\tgs := c.globalState\n\n\t\tuserinfo, err := promptUserAuthForm(gs)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\terr = authenticateUserToken(gs, &newCloudConf, currentJSONConfigRaw,\n\t\t\tuserinfo.token, userinfo.stack)","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/grafana/k6/blob/9cb32757e54f84015838815076e576e857fed833/internal/cmd/cloud_login.go#L89-L125","documentation":"In `k6 cloud login`, the non-interactive branch activates when either -t/--token or --stack was passed. It then requires BOTH values; if the stack flag is absent (or passed but empty), login stops with this error before contacting the API. The stack may be a full URL (https://my-team.grafana.net) or a slug (my-team).","triggerScenarios":"Running `k6 cloud login -t <token>` without --stack, or `k6 cloud login --stack \"\"` — the switch case at cloud_login.go:105 fires because tokenInput is valid, then the stack check at line 106 fails.","commonSituations":"Muscle memory from older k6 where a token alone was enough; CI scripts updated half-way (token added, stack forgotten); empty stack variable interpolated into --stack \"$STACK\" with STACK unset.","solutions":["Add the stack flag: `k6 cloud login -t <token> --stack my-team`","Or drop both flags and use the fully interactive prompt, which asks for token and stack in turn","In scripts, guard that both variables are non-empty before invoking k6 cloud login"],"exampleFix":"# before\nk6 cloud login -t glc_ey...            # -> stack value is required\n\n# after\nk6 cloud login -t glc_ey... --stack my-team","handlingStrategy":"validation","validationCode":": \"${K6_CLOUD_TOKEN:?token required}\"\n: \"${K6_STACK:?stack required (slug or URL, e.g. my-team)}\"\nk6 cloud login -t \"$K6_CLOUD_TOKEN\" --stack \"$K6_STACK\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember the rule: if either -t or --stack is passed, BOTH are required","Default empty variables before interpolating flags in scripts","For exploratory use, run bare `k6 cloud login` and let the prompts guide you"],"tags":["k6","cloud","login","cli-flags","stack"],"backgroundTag":"missing-required-flag","analyzedSha":"9cb32757e54f84015838815076e576e857fed833","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}