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`, 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.
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 93accf6570)
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
Example fix
# before k6 cloud login --token "$K6_CLOUD_TOKEN" # ERR: stack value is required # after k6 cloud login --token "$K6_CLOUD_TOKEN" --stack "my-team" # or: k6 cloud login (interactive prompts)
Defensive patterns
Strategy: validation
Validate before calling
# non-interactive login requires BOTH values; assert before invoking
: "${K6_CLOUD_TOKEN:?token required}"
: "${K6_CLOUD_STACK:?stack required}"
k6 cloud login --token "$K6_CLOUD_TOKEN" --stack "$K6_CLOUD_STACK" Prevention
- 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
When it happens
Trigger: `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).
Common situations: 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.
Related errors
- Run `k6 cloud login` to authenticate, or check the docs for
- token value is required but it was not passed or is empty
- access token not configured
- token cannot be empty
- stack cannot be empty
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/4b35cc7c32026f2d.
Report an issue: GitHub.