{"record":{"id":"1ab21553170d3875","repo":"grafana/k6","slug":"token-value-is-required-but-it-was-not-passed-or-i","errorCode":null,"errorMessage":"token value is required but it was not passed or is empty","messagePattern":"token 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":110,"sourceCode":"\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)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/grafana/k6/blob/9cb32757e54f84015838815076e576e857fed833/internal/cmd/cloud_login.go#L92-L128","documentation":"The token-side counterpart in `k6 cloud login`'s non-interactive branch: when -t/--token or --stack is passed, both are mandatory, and a missing or empty token value fails immediately at cloud_login.go:109 before any network call.","triggerScenarios":"Running `k6 cloud login --stack my-team` without -t, or passing an empty token such as `-t \"\"` / `-t \"$TOKEN\"` with TOKEN unset; the branch triggers because stackInput is valid.","commonSituations":"Automation scripts referencing an unset or misnamed secret variable; pasting the stack first and forgetting the token; shell quoting that expands to an empty string.","solutions":["Pass the token too: `k6 cloud login -t <token> --stack my-team`","Generate the token in Grafana Cloud (Access Policies / k6 tokens) if you don't have one","In CI, assert the secret is non-empty before calling k6 cloud login","Or use the interactive form (no flags) to be prompted for both"],"exampleFix":"# before\nk6 cloud login --stack my-team          # -> token value is required\n\n# after\nk6 cloud login -t glc_ey... --stack my-team","handlingStrategy":"validation","validationCode":"test -n \"$K6_CLOUD_TOKEN\" || { echo 'K6_CLOUD_TOKEN secret is empty'; exit 1; }\ntest -n \"$K6_STACK\" || { echo 'K6_STACK is empty'; exit 1; }\nk6 cloud login -t \"$K6_CLOUD_TOKEN\" --stack \"$K6_STACK\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create the Grafana Cloud token before scripting login","Assert secrets are non-empty in CI before invoking k6 (failed secret fetch often yields '')","Prefer non-interactive login (-t/--stack) in automation; keep interactive login for humans"],"tags":["k6","cloud","login","cli-flags","api-token"],"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"}