{"record":{"id":"d3a720283e168029","repo":"grafana/k6","slug":"stack-id-d-overflows-int32","errorCode":null,"errorMessage":"stack ID %d overflows int32","messagePattern":"stack ID (.+?) overflows int32","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/v6/client.go","lineNumber":50,"sourceCode":"\t}\n\n\tcfg := clientcfg.New(host, version, \"Global k6 Cloud API.\", timeout)\n\n\tc := &Client{\n\t\tapiClient: k6cloud.NewAPIClient(cfg),\n\t\ttoken:     token,\n\t\tbaseURL:   fmt.Sprintf(\"%s/cloud/v6\", host),\n\t\tlogger:    logger,\n\t}\n\treturn c, nil\n}\n\n// SetStackID sets the stack ID for the client. It returns an error if\n// stackID does not fit in the int32 range the underlying SDK requires for\n// the X-Stack-Id header.\nfunc (c *Client) SetStackID(stackID int64) error {\n\tif stackID < math.MinInt32 || stackID > math.MaxInt32 {\n\t\treturn fmt.Errorf(\"stack ID %d overflows int32\", stackID)\n\t}\n\tc.stackID = int32(stackID)\n\treturn nil\n}\n\n// BaseURL returns configured host.\nfunc (c *Client) BaseURL() string {\n\treturn c.baseURL\n}\n\n// CheckResponse checks the parsed response.\n// It returns nil if the code is in the successful range,\n// otherwise it tries to parse the body and return a parsed error.\nfunc CheckResponse(r *http.Response, err error) error {\n\tif err != nil {\n\t\tvar aerr *k6cloud.GenericOpenAPIError\n\t\tif !errors.As(err, &aerr) {\n\t\t\treturn err","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cloudapi/v6/client.go#L32-L68","documentation":"SetStackID rejects a stack ID that does not fit in a signed 32-bit integer. The underlying k6 Cloud OpenAPI Go SDK sends the stack ID as the X-Stack-Id header, which is typed int32, so the client validates the int64 configuration value before narrowing it. In the CLI this value comes from the consolidated cloud configuration (flags, K6_CLOUD_STACK_ID, or the on-disk config written by `k6 cloud login`).","triggerScenarios":"Calling cloudapiv6.Client.SetStackID with stackID < math.MinInt32 or > math.MaxInt32 (e.g. 5000000000). Via the CLI: any cloud command whose resolved K6_CLOUD_STACK_ID or stored login config contains a corrupted or mistyped number.","commonSituations":"CI pipelines that template the wrong variable (a project or org ID instead of the stack ID); a typo or truncated-then-garbage value in K6_CLOUD_STACK_ID; a hand-edited or stale config.json from an older k6 version.","solutions":["Re-run `k6 cloud login` so the server returns and stores the correct stack ID","Fix or unset K6_CLOUD_STACK_ID; real stack IDs are small integers, not billions","Check the on-disk cloud config (read via readDiskConfig) for a bad stack-id value and correct it","If calling SetStackID from Go code, range-check the value against math.MinInt32/math.MaxInt32 first"],"exampleFix":"# before\nK6_CLOUD_STACK_ID=5000000000 k6 cloud script.js\n# after\nK6_CLOUD_STACK_ID=1234567 k6 cloud script.js","handlingStrategy":"validation","validationCode":"stackID, err := strconv.ParseInt(os.Getenv(\"K6_CLOUD_STACK_ID\"), 10, 64)\nif err != nil || stackID < math.MinInt32 || stackID > math.MaxInt32 {\n    log.Fatalf(\"invalid K6_CLOUD_STACK_ID: must be an int32-range integer\")\n}","typeGuard":"func isValidStackID(id int64) bool {\n    return id >= math.MinInt32 && id <= math.MaxInt32\n}","tryCatchPattern":null,"preventionTips":["Prefer `k6 cloud login` over hand-setting stack IDs so the value always comes from the server","In CI, assert the injected stack ID parses as a small integer before invoking k6","Never reuse project, org, or account IDs in place of the stack ID"],"tags":["go","cloud-api","validation","numeric-overflow","configuration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}