grafana/k6 · error

token cannot be empty

Error message

token cannot be empty

What it means

Raised by the interactive login form (promptUserAuthForm): the user submitted the Token field and, after TrimSpace, the value is empty. It is a pure input-validation error — k6 refuses to attempt authentication with a blank token because the API would reject it anyway.

Source

Thrown at internal/cmd/cloud_login.go:183

			"Please, consult the documentation for instructions on how to generate one:\n" +
			"https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication",
		Fields: []ui.Field{
			ui.PasswordField{
				Key:   "Token",
				Label: "Token",
			},
		},
	}
	if !term.IsTerminal(int(syscall.Stdin)) { //nolint:unconvert
		gs.Logger.Warn("Stdin is not a terminal, falling back to plain text input")
	}
	tokenVals, err := tokenForm.Run(gs.Stdin, gs.Stdout)
	if err != nil {
		return userAuthForm{}, err
	}
	token := strings.TrimSpace(tokenVals["Token"])
	if token == "" {
		return userAuthForm{}, errors.New("token cannot be empty")
	}

	/* Stack form */
	stackForm := ui.Form{
		Banner: "\nEnter the stack where you want to run k6's commands by default.\n" +
			"You can enter a full URL (e.g. https://my-team.grafana.net) or just the slug (e.g. my-team):",
		Fields: []ui.Field{
			ui.StringField{
				Key:   "Stack",
				Label: "Stack",
			},
		},
	}
	stackVals, err := stackForm.Run(gs.Stdin, gs.Stdout)
	if err != nil {
		return userAuthForm{}, err
	}
	stack := strings.TrimSpace(stackVals["Stack"])

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-run `k6 cloud login` and paste a real token — create one in Grafana Cloud under the k6 app (API tokens)
  2. Make sure the paste contains no leading/trailing whitespace issues (k6 trims, but the body must be non-empty)
  3. If pasting into the terminal is unreliable, use the non-interactive form: `k6 cloud login --token <TOKEN> --stack <stack>`

Example fix

# before
$ k6 cloud login
  ? Token: <presses Enter with empty input>   # ERR: token cannot be empty

# after
$ k6 cloud login
  ? Token: eyJr...pasted-api-token
  ? Stack: my-team
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Running plain `k6 cloud login`, pressing Enter on the Token prompt without typing anything, or pasting only whitespace/newlines.

Common situations: Paste failure into the terminal (bracketed paste off, clipboard empty); user pressing Enter to 'skip'; terminal issues swallowing the paste. Re-running the command and pasting carefully resolves it.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/ce2f859b402bd2c0. Report an issue: GitHub.