grafana/k6 · error
%s: %w.\n%w
Error message
%s: %w.\n%w
What it means
checkCloudLoginFor returns this error when the consolidated cloud configuration contains no access token: Token is invalid (unset) or the empty string. The message wraps errMissingToken ('access token not configured') together with errCloudAuth, which points at `k6 cloud login` and the token documentation. Every cloud command builds its client via newCloudV6ClientFromConfig, which runs this check before any network call.
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 93accf6570)
Solutions
- Run `k6 cloud login` (or `k6 cloud login --token <api-token>`)
- Set K6_CLOUD_TOKEN to a valid API token in the environment/CI
- If the variable is already set, verify it is exported, non-empty, and has no stray quotes or whitespace
Example fix
# before k6 cloud script.js # no token anywhere # after export K6_CLOUD_TOKEN=eyJr...== k6 cloud script.js
Defensive patterns
Strategy: validation
Validate before calling
if os.Getenv("K6_CLOUD_TOKEN") == "" {
log.Fatal("K6_CLOUD_TOKEN not set; run `k6 cloud login` first")
} Prevention
- Make `k6 cloud login` (or token injection) a setup step in CI before any cloud command
- Fail pipelines early with a pre-flight env check instead of deep inside k6
- Store the token in a secrets manager and export it verbatim, without quotes or whitespace
When it happens
Trigger: Running `k6 cloud`, the cloud-execution path of `k6 cloud run`, or any cloud listing sub-command when the token is absent from flags, K6_CLOUD_TOKEN, and the on-disk login config.
Common situations: Fresh install without `k6 cloud login`; CI where the secret is empty, not exported, or the env var name is misspelled; the token key was deleted from the stored config; migrating scripts between machines without copying credentials.
Related errors
- access token not configured
- Run `k6 cloud login` to authenticate, or check the docs for
- token value is required but it was not passed or is empty
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN m
- K6_CLOUD_LOGS_PUSH_URL requires K6_CLOUD_TEST_RUN_TOKEN
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/ce21d20ede13e616.
Report an issue: GitHub.