grafana/k6 · error
stack ID %d overflows int32
Error message
stack ID %d overflows int32
What it means
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`).
Source
Thrown at internal/cloudapi/v6/client.go:50
}
cfg := clientcfg.New(host, version, "Global k6 Cloud API.", timeout)
c := &Client{
apiClient: k6cloud.NewAPIClient(cfg),
token: token,
baseURL: fmt.Sprintf("%s/cloud/v6", host),
logger: logger,
}
return c, nil
}
// SetStackID sets the stack ID for the client. It returns an error if
// stackID does not fit in the int32 range the underlying SDK requires for
// the X-Stack-Id header.
func (c *Client) SetStackID(stackID int64) error {
if stackID < math.MinInt32 || stackID > math.MaxInt32 {
return fmt.Errorf("stack ID %d overflows int32", stackID)
}
c.stackID = int32(stackID)
return nil
}
// BaseURL returns configured host.
func (c *Client) BaseURL() string {
return c.baseURL
}
// CheckResponse checks the parsed response.
// It returns nil if the code is in the successful range,
// otherwise it tries to parse the body and return a parsed error.
func CheckResponse(r *http.Response, err error) error {
if err != nil {
var aerr *k6cloud.GenericOpenAPIError
if !errors.As(err, &aerr) {
return errView on GitHub (pinned to 93accf6570)
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
Example fix
# before K6_CLOUD_STACK_ID=5000000000 k6 cloud script.js # after K6_CLOUD_STACK_ID=1234567 k6 cloud script.js
Defensive patterns
Strategy: validation
Validate before calling
stackID, err := strconv.ParseInt(os.Getenv("K6_CLOUD_STACK_ID"), 10, 64)
if err != nil || stackID < math.MinInt32 || stackID > math.MaxInt32 {
log.Fatalf("invalid K6_CLOUD_STACK_ID: must be an int32-range integer")
} Type guard
func isValidStackID(id int64) bool {
return id >= math.MinInt32 && id <= math.MaxInt32
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- stack URL is required to validate token
- 104
- sigV4 config `Region`, `AwsAccessKeyID`, `AwsSecretAccessKey
- failed to parse retryable status codes: %w
- create or find load test: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/d3a720283e168029.
Report an issue: GitHub.