{"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/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud_login.go#L89-L125","documentation":"In `k6 cloud login`, when either --token or --stack is supplied non-interactively, BOTH must be supplied and non-empty. This branch fires when the token was provided (or a stack value arrived empty) but the stack input is invalid or empty — non-interactive login is all-or-nothing by design, because there is no prompt to fill the gap.","triggerScenarios":"`k6 cloud login --token <TOKEN>` without --stack; or a --stack flag resolving to an empty string while --token is set (e.g. an empty value from a wrapper script variable).","commonSituations":"CI login scripts that pass the token via flag but expect the stack from config; a $K6_CLOUD_STACK shell variable that is empty in the job, interpolated into the flag as an empty string.","solutions":["Supply both flags together: `k6 cloud login --token <TOKEN> --stack <slug-or-URL>`","Or drop both flags and use the interactive form `k6 cloud login`, which prompts for each field","If the stack comes from a variable, assert it is non-empty before invoking the command"],"exampleFix":"# before\nk6 cloud login --token \"$K6_CLOUD_TOKEN\"   # ERR: stack value is required\n\n# after\nk6 cloud login --token \"$K6_CLOUD_TOKEN\" --stack \"my-team\"\n# or: k6 cloud login   (interactive prompts)","handlingStrategy":"validation","validationCode":"# non-interactive login requires BOTH values; assert before invoking\n: \"${K6_CLOUD_TOKEN:?token required}\" \n: \"${K6_CLOUD_STACK:?stack required}\" \nk6 cloud login --token \"$K6_CLOUD_TOKEN\" --stack \"$K6_CLOUD_STACK\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --token and --stack together; neither alone works non-interactively","In scripts, use shell parameter expansion guards so empty variables fail before k6 does","Prefer the interactive `k6 cloud login` when you cannot guarantee both values"],"tags":["cloud","login","cli","auth","flags"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}