grafana/k6 · error
stack ID overflows int32
Error message
stack ID %d overflows int32
What it means
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.
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
Example fix
// before
if err := client.SetStackID(cfg.StackID.Int64); err != nil { return err }
// after
stackID := cfg.StackID.Int64
if stackID < math.MinInt32 || stackID > math.MaxInt32 {
return fmt.Errorf("configured stack ID %d is invalid; re-run `k6 cloud login`", stackID)
}
if err := client.SetStackID(stackID); err != nil { return err } Defensive patterns
Strategy: validation
Validate before calling
func validStackID(id int64) error {
if id == 0 { return fmt.Errorf("stack ID is zero; run `k6 cloud login`") }
if id < math.MinInt32 || id > math.MaxInt32 { return fmt.Errorf("stack ID %d out of int32 range; config is corrupt", id) }
return nil
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- env var ' ' is not a valid boolean value
- a function is expected as the second argument of…
- can't have two secret sources that are default ones, second…
- cannot be null or undefined
- cookie name must be set: %#v
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/d3a720283e168029.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cloudapi/v6/client.go:51
}
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 {
if _, ok := errors.AsType[*k6cloud.GenericOpenAPIError](err); !ok {
return err
}View on GitHub (pinned to 8d06114777)