{"record":{"id":"e6abddb3b541d245","repo":"grafana/k6","slug":"value-d-overflows-int32","errorCode":null,"errorMessage":"value %d overflows int32","messagePattern":"value (.+?) overflows int32","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloudapi/provisioning/api.go","lineNumber":298,"sourceCode":"\t\t\t\tPushPeriodSeconds: l.GetPushPeriodSeconds(),\n\t\t\t\tMessageMaxSize:    l.GetMessageMaxSize(),\n\t\t\t\tAllowedLabels:     l.GetAllowedLabels(),\n\t\t\t},\n\t\t},\n\t}\n\n\tif url := res.ArchiveUploadUrl.Get(); url != nil {\n\t\tresp.ArchiveUploadURL = url\n\t}\n\n\treturn resp\n}\n\n// toInt32 safely converts an int64 to int32, returning an error if\n// the value overflows.\nfunc toInt32(v int64) (int32, error) {\n\tif v < math.MinInt32 || v > math.MaxInt32 {\n\t\treturn 0, fmt.Errorf(\"value %d overflows int32\", v)\n\t}\n\treturn int32(v), nil\n}\n\n// closeResponse drains and closes an HTTP response body. It mirrors\n// the v6 package's closeResponse helper.\nfunc closeResponse(res *http.Response, rerr *error) {\n\tif res == nil {\n\t\treturn\n\t}\n\t_, _ = io.Copy(io.Discard, res.Body)\n\tif err := res.Body.Close(); err != nil && *rerr == nil {\n\t\t*rerr = err\n\t}\n}\n","sourceCodeStart":280,"sourceCodeEnd":314,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/cloudapi/provisioning/api.go#L280-L314","documentation":"toInt32 (internal/cloudapi/provisioning/api.go:298) is the shared guard that rejects any int64 outside [-2^31, 2^31-1] before it is placed into an int32-typed SDK field (max_vus, total_duration, archive_size). This message is the root cause wrapped by the 'max_vus:', 'total_duration:', and 'archive_size:' errors from StartLocalExecution; it can also fire directly wherever toInt32 is used.","triggerScenarios":"Any StartLocalExecutionRequest field whose int64 value overflows int32: absurd VU counts, durations expressed in the wrong unit, or archives over 2 GiB.","commonSituations":"Unit confusion in duration math, unvalidated env-var-derived VU counts, and oversized archives are the three realistic producers.","solutions":["Identify which field overflowed from the wrapping prefix (max_vus / total_duration / archive_size)","Correct the value's unit or magnitude at its source (options, duration computation, archive contents)","Add range validation in the caller so the failure is caught with a clearer message before provisioning"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func checkInt32(name string, v int64) error {\n\tif v < math.MinInt32 || v > math.MaxInt32 {\n\t\treturn fmt.Errorf(\"%s %d exceeds int32 range\", name, v)\n\t}\n\treturn nil\n}\nfor _, c := range []struct{ n string; v int64 }{\n\t{\"max_vus\", req.MaxVUs}, {\"total_duration\", req.TotalDuration}, {\"archive_size\", req.ArchiveSize},\n} {\n\tif err := checkInt32(c.n, c.v); err != nil {\n\t\treturn err\n\t}\n}","typeGuard":"func fitsInt32(v int64) bool { return v >= math.MinInt32 && v <= math.MaxInt32 }","tryCatchPattern":"if err := client.StartLocalExecution(ctx, id, req); err != nil {\n\tif strings.Contains(err.Error(), \"overflows int32\") {\n\t\t// a request field is garbage; validate before rebuilding the request\n\t}\n\treturn err\n}","preventionTips":["Validate all three int64 request fields once, at request-build time, with named errors","Reject implausible magnitudes (VUs, seconds, bytes) long before the int32 boundary","Property-test option computation for overflow at the boundaries"],"tags":["validation","int32","overflow","shared-helper"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}