grafana/k6 · error
stack value is required but it was not passed or is empty
Error message
stack value is required but it was not passed or is empty
What it means
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).
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
Example fix
# before k6 cloud login -t glc_ey... # -> stack value is required # after k6 cloud login -t glc_ey... --stack my-team
Defensive patterns
Strategy: validation
Validate before calling
: "${K6_CLOUD_TOKEN:?token required}"
: "${K6_STACK:?stack required (slug or URL, e.g. my-team)}"
k6 cloud login -t "$K6_CLOUD_TOKEN" --stack "$K6_STACK" Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- stack cannot be empty
- token value is required but it was not passed or is empty
- Run `k6 cloud login` to authenticate, or check the docs for…
- token cannot be empty
- 104
AI-assisted analysis of grafana/k6@9cb32757e5 (2026-08-18).
Data as JSON: /api/errors/4b35cc7c32026f2d.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cmd/cloud_login.go:107
show := getNullBool(cmd.Flags(), "show")
reset := getNullBool(cmd.Flags(), "reset")
tokenInput := getNullString(cmd.Flags(), "token")
stackInput := getNullString(cmd.Flags(), "stack")
switch {
case reset.Valid:
newCloudConf.Token = null.StringFromPtr(nil)
newCloudConf.StackID = null.IntFromPtr(nil)
newCloudConf.StackURL = null.StringFromPtr(nil)
newCloudConf.DefaultProjectID = null.IntFromPtr(nil)
printToStdout(c.globalState, "\nToken and stack info have been reset.\n")
case show.Bool:
printConfig(c.globalState, newCloudConf)
return nil
case tokenInput.Valid || stackInput.Valid:
if !stackInput.Valid || stackInput.String == "" {
return errors.New("stack value is required but it was not passed or is empty")
}
if !tokenInput.Valid || tokenInput.String == "" {
return errors.New("token value is required but it was not passed or is empty")
}
err := authenticateUserToken(c.globalState, &newCloudConf, currentJSONConfigRaw, tokenInput.String, stackInput.String)
if err != nil {
return err
}
default:
gs := c.globalState
userinfo, err := promptUserAuthForm(gs)
if err != nil {
return err
}
err = authenticateUserToken(gs, &newCloudConf, currentJSONConfigRaw,
userinfo.token, userinfo.stack)View on GitHub (pinned to 9cb32757e5)