{"record":{"id":"ce21d20ede13e616","repo":"grafana/k6","slug":"s-w-n-w","errorCode":null,"errorMessage":"%s: %w.\\n%w","messagePattern":"(.+?): %w\\.\\\\n%w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":58,"sourceCode":"\terrMissingStackID = errors.New(\"stack ID not configured\")\n\n\t// errNoProjectConfigured is returned by cloud sub-commands that require a\n\t// concrete project to operate on when none can be resolved from the flags,\n\t// the environment, or the logged-in configuration.\n\terrNoProjectConfigured = errors.New(\n\t\t\"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project\",\n\t)\n)\n\n// checkCloudLogin verifies that both a token and a stack are configured.\n// Together they represent a complete Grafana Cloud login.\nfunc checkCloudLogin(conf cloudapi.Config) error {\n\treturn checkCloudLoginFor(conf, cloudRunAuthPrefix)\n}\n\nfunc checkCloudLoginFor(conf cloudapi.Config, prefix string) error {\n\tif !conf.Token.Valid || conf.Token.String == \"\" {\n\t\treturn fmt.Errorf(\"%s: %w.\\n%w\", prefix, errMissingToken, errCloudAuth)\n\t}\n\tif !conf.StackID.Valid || conf.StackID.Int64 == 0 {\n\t\treturn fmt.Errorf(\"%s: %w.\\n%w\", prefix, errMissingStackID, errCloudAuth)\n\t}\n\treturn nil\n}\n\n// newCloudV6ClientFromConfig builds a v6 cloud API client from the on-disk and\n// environment configuration. It verifies that a complete login is configured\n// (using authPrefix in the error message) and wires the resolved stack ID into\n// the client. It returns the client alongside the consolidated cloud config.\nfunc newCloudV6ClientFromConfig(\n\tgs *state.GlobalState, authPrefix string,\n) (*cloudapiv6.Client, cloudapi.Config, error) {\n\tcurrentDiskConf, err := readDiskConfig(gs)\n\tif err != nil {\n\t\treturn nil, cloudapi.Config{}, err\n\t}","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cmd/cloud.go#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nk6 cloud script.js  # no token anywhere\n# after\nexport K6_CLOUD_TOKEN=eyJr...==\nk6 cloud script.js","handlingStrategy":"validation","validationCode":"if os.Getenv(\"K6_CLOUD_TOKEN\") == \"\" {\n    log.Fatal(\"K6_CLOUD_TOKEN not set; run `k6 cloud login` first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["auth","configuration","cloud","token"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}