{"record":{"id":"ded840f2cd7d504f","repo":"apache/beam","slug":"s-passert","errorCode":null,"errorMessage":"%s","messagePattern":"%s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/passert.go","lineNumber":168,"sourceCode":"func fail(s beam.Scope, col beam.PCollection, format string) {\n\tswitch {\n\tcase typex.IsKV(col.Type()):\n\t\tbeam.ParDo0(s, &failKVFn{Format: format}, col)\n\n\tcase typex.IsCoGBK(col.Type()):\n\t\tbeam.ParDo0(s, &failGBKFn{Format: format}, col)\n\n\tdefault:\n\t\tbeam.ParDo0(s, &failFn{Format: format}, col)\n\t}\n}\n\ntype failFn struct {\n\tFormat string `json:\"format\"`\n}\n\nfunc (f *failFn) ProcessElement(x beam.X) error {\n\treturn errors.Errorf(f.Format, x)\n}\n\ntype failKVFn struct {\n\tFormat string `json:\"format\"`\n}\n\nfunc (f *failKVFn) ProcessElement(x beam.X, y beam.Y) error {\n\treturn errors.Errorf(f.Format, fmt.Sprintf(\"(%v,%v)\", x, y))\n}\n\ntype failGBKFn struct {\n\tFormat string `json:\"format\"`\n}\n\nfunc (f *failGBKFn) ProcessElement(x beam.X, _ func(*beam.Y) bool) error {\n\treturn errors.Errorf(f.Format, fmt.Sprintf(\"(%v,*)\", x))\n}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/passert.go#L150-L186","documentation":"passert.Failures (via failFn) is a test-only DoFn in Apache Beam Go SDK that formats and returns an error when any element reaches it. The error message is the user-supplied format string with the failing element substituted. It is thrown because a pipeline assertion (Equals/Sum/etc.) found data that should not exist, i.e. the assertion failed.","triggerScenarios":"Running a pipeline with passert.Equals / passert.Sum (or any check that pipes unexpected elements into Failures): an element was emitted downstream and passert routes it to failFn.ProcessElement, which returns errors.Errorf(f.Format, x).","commonSituations":"Unit/integration tests of Beam pipelines: expected outputs don't match actual outputs due to a broken DoFn, wrong input data, nondeterministic pipeline logic, or incorrect expected fixture values.","solutions":["Inspect the error message element to find which records failed the assertion","Compare expected vs actual values; fix the transform producing wrong output","If the expected data is wrong, correct the passert expected list/sum in the test","Re-run the pipeline with logging to trace which stage emitted the bad element"],"exampleFix":"// before: assertion fails with mismatched element\nEquals(p, col, \"bad-output\")\n// after: correct expected value or fix the transform emitting it\nEquals(p, col, \"good-output\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := pipelineRun(); err != nil {\n\tif strings.Contains(err.Error(), \"passert\") {\n\t\t// assertion failure: log actual vs expected, fail test with context\n\t\tt.Fatalf(\"assertion failed: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Verify transform output with logging before adding assertions","Keep expected fixtures in sync with the transform contract","Write smaller assertions per stage to localize failures"],"tags":["testing","assertion","apache-beam"],"backgroundTag":"schema-validation-failed","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"}