{"record":{"id":"daf94044baee1360","repo":"apache/beam","slug":"tryequalsfloat-failed-v","errorCode":null,"errorMessage":"TryEqualsFloat failed: %v","messagePattern":"TryEqualsFloat failed: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/floats.go","lineNumber":42,"sourceCode":"\t\"github.com/apache/beam/sdks/v2/go/pkg/beam\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/register\"\n)\n\nfunc init() {\n\tregister.DoFn2x1[[]byte, func(*beam.T) bool, error]((*boundsFn)(nil))\n\tregister.DoFn3x1[[]byte, func(*beam.T) bool, func(*beam.T) bool, error]((*thresholdFn)(nil))\n\tregister.Emitter1[beam.T]()\n\tregister.Iter1[beam.T]()\n}\n\n// EqualsFloat calls into TryEqualsFloat, checkong that two PCollections of non-complex\n// numeric types are equal, with each element being within a provided threshold of an\n// expected value. Panics if TryEqualsFloat returns an error.\nfunc EqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64) {\n\tif err := TryEqualsFloat(s, observed, expected, threshold); err != nil {\n\t\tpanic(fmt.Sprintf(\"TryEqualsFloat failed: %v\", err))\n\t}\n}\n\n// TryEqualsFloat checks that two PCollections of floats are equal, with each element\n// being within a specified threshold of its corresponding element. Both PCollections\n// are loaded into memory, sorted, and compared element by element. Returns an error if\n// the PCollection types are complex or non-numeric.\nfunc TryEqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64) error {\n\terrorStrings := []string{}\n\tobservedT := beam.ValidateNonCompositeType(observed)\n\tif obsErr := validateNonComplexNumber(observedT.Type()); obsErr != nil {\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"observed PCollection has incompatible type: %v\", obsErr))\n\t}\n\texpectedT := beam.ValidateNonCompositeType(expected)\n\tvalidateNonComplexNumber(expectedT.Type())\n\tif expErr := validateNonComplexNumber(expectedT.Type()); expErr != nil {\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"expected PCollection has incompatible type: %v\", expErr))\n\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/floats.go#L24-L60","documentation":"passert.EqualsFloat is the panicking wrapper around TryEqualsFloat, which loads two float PCollections into memory, sorts them, and compares element-by-element within a threshold. If TryEqualsFloat returns any error (pipeline construction/validation issue), EqualsFloat panics so the test fails immediately.","triggerScenarios":"Calling passert.EqualsFloat(s, observed, expected, threshold) where TryEqualsFloat fails — most commonly when observed or expected is not a non-complex numeric PCollection (e.g. complex numbers or non-numeric element types).","commonSituations":"Pipeline tests asserting equality on float collections whose element type is complex128, or passing PCollections produced by a transform that changed the element type.","solutions":["Call passert.TryEqualsFloat directly and handle/log the returned error instead of panicking.","Ensure both PCollections have non-complex numeric element types before asserting.","Print the underlying error via a small wrapper to diagnose the root cause."],"exampleFix":"// before\npassert.EqualsFloat(s, observed, expected, 1e-6) // panics on error\n// after\nif err := passert.TryEqualsFloat(s, observed, expected, 1e-6); err != nil {\n    t.Fatalf(\"float assertion failed: %v\", err)\n}","handlingStrategy":"validation","validationCode":"// check element types are non-complex numeric before asserting\nfunc isNonComplexNumeric(t typex.FullType) bool {\n    switch t.Type().Kind() {\n    case reflect.Float32, reflect.Float64, reflect.Int, reflect.Int32, reflect.Int64:\n        return true\n    }\n    return false\n}","typeGuard":null,"tryCatchPattern":"func safeEqualsFloat(t *testing.T, s beam.Scope, obs, exp beam.PCollection, th float64) {\n    defer func() { if r := recover(); r != nil { t.Fatalf(\"EqualsFloat panicked: %v\", r) } }()\n    passert.EqualsFloat(s, obs, exp, th)\n}","preventionTips":["Prefer TryEqualsFloat in test helpers to get errors instead of panics","Assert only on float32/float64 (and int) element PCollections","Verify upstream transform output types before passert calls"],"tags":["go","beam","passert","testing","panic"],"backgroundTag":"invalid-argument-value","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"}