{"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":51,"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\tif _, ok := errors.AsType[*k6cloud.GenericOpenAPIError](err); !ok {\n\t\t\treturn err\n\t\t}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/grafana/k6/blob/8d06114777191d21ef885d05c5f8aa9e1ed838ae/internal/cloudapi/v6/client.go#L33-L69","documentation":"Client.SetStackID refuses a stackID that does not fit in the int32 range required by the X-Stack-Id header of the generated cloud SDK. It is a pure bounds check (math.MinInt32..math.MaxInt32), so the value came from configuration and is implausible for a real Grafana Cloud stack ID.","triggerScenarios":"K6_CLOUD_STACK_ID or the on-disk login config containing a garbage 64-bit number (e.g. a timestamp, a token fragment, or a mis-parsed value), or programmatic callers passing an uninitialized/overflowed int64.","commonSituations":"Config files hand-edited or generated by other tooling, env var name confusion where a project ID or epoch millis land in the stack ID field, or corrupted state after partial writes.","solutions":["Inspect the resolved value: `k6 cloud login` rewrites the whole auth block cleanly — usually the fastest fix","Check K6_CLOUD_STACK_ID (and the config file) for a copy-paste of the wrong number","If computing the stack ID in code, validate the int64 against int32 bounds before calling SetStackID and fail with a clear config error"],"exampleFix":"// before\nif err := client.SetStackID(cfg.StackID.Int64); err != nil { return err }\n\n// after\nstackID := cfg.StackID.Int64\nif stackID < math.MinInt32 || stackID > math.MaxInt32 {\n    return fmt.Errorf(\"configured stack ID %d is invalid; re-run `k6 cloud login`\", stackID)\n}\nif err := client.SetStackID(stackID); err != nil { return err }","handlingStrategy":"validation","validationCode":"func validStackID(id int64) error {\n    if id == 0 { return fmt.Errorf(\"stack ID is zero; run `k6 cloud login`\") }\n    if id < math.MinInt32 || id > math.MaxInt32 { return fmt.Errorf(\"stack ID %d out of int32 range; config is corrupt\", id) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat out-of-range stack IDs as configuration corruption — re-login rather than clamping","Generate login config only through k6 itself, not scripts writing raw fields","Validate env-provided IDs before they reach the client"],"tags":["config","validation","stack-id","overflow"],"backgroundTag":"numeric-overflow","analyzedSha":"8d06114777191d21ef885d05c5f8aa9e1ed838ae","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}