From 6b065aa54c69c61ccb30e294a41a4c4533942b83 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sat, 18 Jul 2026 14:18:33 +0530 Subject: [PATCH] fix(querybuildertypesv5): guard float overflow in roundToNonZeroDecimals (#12151) math.Round(val*multiplier)/multiplier overflows to +Inf for finite values near math.MaxFloat64, turning a valid series value into JSON-unmarshalable Inf downstream. Return the value unrounded when the scaled intermediate overflows. Co-authored-by: Claude Fable 5 --- pkg/types/querybuildertypes/querybuildertypesv5/resp.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/types/querybuildertypes/querybuildertypesv5/resp.go b/pkg/types/querybuildertypes/querybuildertypesv5/resp.go index c0aa6c260b4..190670d5aaa 100644 --- a/pkg/types/querybuildertypes/querybuildertypesv5/resp.go +++ b/pkg/types/querybuildertypes/querybuildertypesv5/resp.go @@ -328,6 +328,11 @@ func roundToNonZeroDecimals(val float64, n int) float64 { // Round to n decimal places multiplier := math.Pow(10, float64(n)) rounded := math.Round(val*multiplier) / multiplier + if math.IsInf(rounded, 0) { + // val*multiplier overflowed for near-max float64 values; the + // finite input must stay finite or the JSON encoder rejects it. + return val + } // If the result is a whole number, return it as such if rounded == math.Trunc(rounded) {