grafana/k6 · error

token cannot be empty

Error message

token cannot be empty

What it means

Raised by the interactive login prompt (promptUserAuthForm) when the user submits the token form with an empty or whitespace-only token. The input is TrimSpace'd before the check, so spaces-only input also fails. This is the interactive path taken when `k6 cloud login` is run with no -t/--stack flags.

Solutions

  1. Create a token in Grafana Cloud (Access Policies with the k6 scope) and paste it at the prompt
  2. For automation, skip the prompt entirely: `k6 cloud login -t <token> --stack <stack>`
  3. Make sure the terminal has focus when pasting; retype if the paste failed

Example fix

# before (interactive, empty input)
$ k6 cloud login
> Enter your token: <presses Enter>     # -> token cannot be empty

# after (non-interactive)
$ k6 cloud login -t glc_ey... --stack my-team
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Running plain `k6 cloud login` and pressing Enter on the token field without typing anything, or pasting only whitespace; also when a non-TTY stdin immediately sends an empty line (the form warns 'Stdin is not a terminal' and falls back to plain input).

Common situations: Paste didn't land in the terminal; CI/automation accidentally invoking interactive login with piped empty stdin; users unsure what to enter (a Grafana Cloud token is expected, not username/password).

Related errors


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

Appendix: 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 9cb32757e5)