{"record":{"id":"b8e378fb985516fe","repo":"apache/beam","slug":"unexpected-number-type-v-b8e378","errorCode":null,"errorMessage":"Unexpected number type: %v","messagePattern":"Unexpected number type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/stats/min_switch.tmpl","lineNumber":30,"sourceCode":"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\npackage stats\n\nimport (\n    \"fmt\"\n    \"reflect\"\n)\n\nfunc findMinFn(t reflect.Type) any {\n    switch t.String() {\n{{- range .X}}\n    case \"{{.Type}}\":\n\t\treturn min{{.Name}}Fn\n{{- end}}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Unexpected number type: %v\", t))\n\t}\n}\n{{range .X}}\nfunc min{{.Name}}Fn(x, y {{.Type}}) {{.Type}} {\n\tif x < y {\n\t\treturn x\n\t}\n\treturn y\n}\n{{end}}\n","sourceCodeStart":12,"sourceCodeEnd":41,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/stats/min_switch.tmpl#L12-L41","documentation":"In Apache Beam Go SDK's stats package, the min helpers dispatch to a numeric-specific min function via a generated switch on reflect.Type. When the element type is not one of the generated numeric instantiations, the default branch panics with 'Unexpected number type'. It enforces that Min is only applied to supported numeric PCollections.","triggerScenarios":"Calling stats.Min on a PCollection whose element reflect.Type is not in the generated case list (string, struct, interface{}, bool, or an alias/defined type not covered).","commonSituations":"Accidentally applying Min to a string collection, defined types like type Celsius float64 whose reflect string doesn't match, or upstream transforms that erased concrete numeric types.","solutions":["Apply stats.Min only to PCollections of supported numeric element types.","Insert beam.Map to convert elements to a supported numeric type before Min.","Convert defined/aliased numeric types with an explicit cast DoFn to base types.","Extend the template's type list and regenerate if a new numeric type is genuinely needed."],"exampleFix":"// before\ntype Temp float64\nstats.Min(s, temps) // panics for unregistered defined type\n\n// after\nraw := beam.Map(s, func(t Temp) float64 { return float64(t) }, temps)\nstats.Min(s, raw)","handlingStrategy":"validation","validationCode":"// Ensure Min input is a supported numeric type at graph construction\nif !strings.Contains(\"|int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float32|float64|\", col.Type().String()+\"|\") {\n    panic(\"stats.Min requires a supported numeric element type\")\n}","typeGuard":"func isMinSupported(v any) bool {\n    switch reflect.ValueOf(v).Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n        reflect.Float32, reflect.Float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"Unexpected number type\") {\n            log.Printf(\"stats.Min called with unsupported element type: %v\", r)\n        }\n        panic(r)\n    }\n}()","preventionTips":["Only apply stats.Min to numeric PCollections.","Map defined/aliased numeric types to base types upstream.","Validate element kind with a cheap beam.Map assertion in tests.","Keep pipeline reshapes from erasing concrete numeric types to interface{}."],"tags":["go","beam","stats","types"],"backgroundTag":"unsupported-dtype","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}