{"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/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L40-L76","documentation":"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`.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Run `k6 cloud login` to store token and stack together","Or export K6_CLOUD_TOKEN=<api-token> (service accounts in CI) alongside K6_CLOUD_STACK_ID","Or pass --token on the command line for one-off runs","Verify afterwards with `k6 cloud login show` (or inspect the config file) that the token is populated"],"exampleFix":"# before\nk6 cloud run script.js   # ERR: access token not configured\n\n# after\nexport K6_CLOUD_TOKEN=\"$K6_TOKEN\"\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"if !conf.Token.Valid || conf.Token.String == \"\" {\n    return fmt.Errorf(\"no token: set K6_CLOUD_TOKEN or run `k6 cloud login`\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `k6 cloud login` as the first step on any new machine/CI image","Assert required secrets exist in CI before invoking k6","After `k6 cloud logout`, grep your pipelines for stale cloud invocations"],"tags":["auth","missing-token","cloud-api","config","cli"],"backgroundTag":"missing-api-token","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}