grafana/k6 · error

: .\n

Error message

%s: %w.\n%w

What it means

checkCloudLoginFor found no usable access token: conf.Token is invalid/null or an empty string, so `k6 cloud` (and other cloud commands sharing the check) abort before any API call. The message composes the command-specific prefix ('Running cloud tests requires auth settings'), the 'access token not configured' sentinel, and the errCloudAuth hint pointing at `k6 cloud login`.

Solutions

  1. Run `k6 cloud login` to store token and stack together
  2. Or export K6_CLOUD_TOKEN=<api-token> (service accounts in CI) alongside K6_CLOUD_STACK_ID
  3. Or pass --token on the command line for one-off runs
  4. Verify afterwards with `k6 cloud login show` (or inspect the config file) that the token is populated

Example fix

# before
k6 cloud run script.js   # ERR: access token not configured

# after
export K6_CLOUD_TOKEN="$K6_TOKEN"
k6 cloud run script.js
Defensive patterns

Strategy: validation

Validate before calling

if !conf.Token.Valid || conf.Token.String == "" {
    return fmt.Errorf("no token: set K6_CLOUD_TOKEN or run `k6 cloud login`")
}

Prevention

When it happens

Trigger: Fresh machine with no login, K6_CLOUD_TOKEN unset or set to empty in the environment, --token flag omitted, or a partially deleted config file (token cleared but stack ID left).

Common situations: New CI pipelines that copied the k6 invocation but not the token secret, local config at ~/.config/loadimpact/k6/config (or K6_CONFIG_PATH) truncated or reset, or token removed by `k6 cloud logout` while scripts still run cloud tests.

Related errors


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

Appendix: source

Thrown at internal/cmd/cloud.go:58

	errMissingStackID = errors.New("stack ID not configured")

	// errNoProjectConfigured is returned by cloud sub-commands that require a
	// concrete project to operate on when none can be resolved from the flags,
	// the environment, or the logged-in configuration.
	errNoProjectConfigured = errors.New(
		"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project",
	)
)

// checkCloudLogin verifies that both a token and a stack are configured.
// Together they represent a complete Grafana Cloud login.
func checkCloudLogin(conf cloudapi.Config) error {
	return checkCloudLoginFor(conf, cloudRunAuthPrefix)
}

func checkCloudLoginFor(conf cloudapi.Config, prefix string) error {
	if !conf.Token.Valid || conf.Token.String == "" {
		return fmt.Errorf("%s: %w.\n%w", prefix, errMissingToken, errCloudAuth)
	}
	if !conf.StackID.Valid || conf.StackID.Int64 == 0 {
		return fmt.Errorf("%s: %w.\n%w", prefix, errMissingStackID, errCloudAuth)
	}
	return nil
}

// newCloudV6ClientFromConfig builds a v6 cloud API client from the on-disk and
// environment configuration. It verifies that a complete login is configured
// (using authPrefix in the error message) and wires the resolved stack ID into
// the client. It returns the client alongside the consolidated cloud config.
func newCloudV6ClientFromConfig(
	gs *state.GlobalState, authPrefix string,
) (*cloudapiv6.Client, cloudapi.Config, error) {
	currentDiskConf, err := readDiskConfig(gs)
	if err != nil {
		return nil, cloudapi.Config{}, err
	}

View on GitHub (pinned to 94169daab2)