{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_login.go#L92-L128","documentation":"The mirror case of the stack guard in `k6 cloud login`: when non-interactive input is detected (stack was provided) but the token input is invalid or empty, login refuses to proceed. A stack without a token cannot authenticate, and in non-interactive mode there is nothing to prompt for.","triggerScenarios":"`k6 cloud login --stack my-team` without --token; or a --token flag that resolves to an empty string (empty environment variable interpolated into the command).","commonSituations":"CI job exports the stack but the token secret was not mounted/injected, so $K6_CLOUD_TOKEN expands to empty; token pasted with only whitespace; shell quoting mistakes that swallow the value.","solutions":["Supply both values: `k6 cloud login --token <TOKEN> --stack <slug-or-URL>`","Verify the token variable is actually populated in the environment (`test -n \"$K6_CLOUD_TOKEN\"`)","Use the interactive `k6 cloud login` form, which validates the token is non-empty before submitting"],"exampleFix":"# before\nk6 cloud login --stack my-team   # ERR: token value is required\n\n# after\nk6 cloud login --token \"$K6_CLOUD_TOKEN\" --stack my-team\ntest -n \"$K6_CLOUD_TOKEN\" || { echo \"token missing\"; exit 1; }  # guard in scripts","handlingStrategy":"validation","validationCode":"# assert the secret is present and non-empty before login\ntest -n \"$K6_CLOUD_TOKEN\" || { echo \"K6_CLOUD_TOKEN empty or unset\" >&2; exit 1; }\nk6 cloud login --token \"$K6_CLOUD_TOKEN\" --stack \"$K6_CLOUD_STACK\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inject the token as a CI secret and assert it is non-empty before the login step","Trim whitespace when copying tokens — login rejects blank strings by design","Validate both flag values in one place (wrapper script) so k6 never sees half a login"],"tags":["cloud","login","cli","auth","token"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}