{"record":{"id":"19f646aad5619020","repo":"apache/beam","slug":"panic-err-emitter","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/register/emitter.go","lineNumber":64,"sourceCode":"\te.est = est\n}\n\ntype emit1[T any] struct {\n\temit\n\tn exec.ElementProcessor\n}\n\nfunc (e *emit1[T]) Value() any {\n\treturn e.invoke\n}\n\nfunc (e *emit1[T]) invoke(val T) {\n\te.value = exec.FullValue{Pane: e.pn, Windows: e.ws, Timestamp: e.et, Elm: val}\n\tif e.est != nil {\n\t\t(*e.est).(sdf.TimestampObservingEstimator).ObserveTimestamp(e.et.ToTime())\n\t}\n\tif err := e.n.ProcessElement(e.ctx, &e.value); err != nil {\n\t\tpanic(err)\n\t}\n}\n\ntype emit2[T1, T2 any] struct {\n\temit\n\tn exec.ElementProcessor\n}\n\nfunc (e *emit2[T1, T2]) Value() any {\n\treturn e.invoke\n}\n\nfunc (e *emit2[T1, T2]) invoke(key T1, val T2) {\n\te.value = exec.FullValue{Pane: e.pn, Windows: e.ws, Timestamp: e.et, Elm: key, Elm2: val}\n\tif e.est != nil {\n\t\t(*e.est).(sdf.TimestampObservingEstimator).ObserveTimestamp(e.et.ToTime())\n\t}\n\tif err := e.n.ProcessElement(e.ctx, &e.value); err != nil {","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/register/emitter.go#L46-L82","documentation":"emit1[T].invoke panics with the raw error when the downstream ProcessElement call on the registered element processor fails. Emitters are the optimized runtime path for DoFn output (ProcessContext.Emit); any error from the consuming element handler is turned into a panic so it unwinds through the exec harness and fails the bundle.","triggerScenarios":"Emitting an element from a DoFn (func(T) signature registered via Emitter1/register.Function1x1 style) where the downstream node's ProcessElement returns an error, e.g. encoding failure of the emitted value, downstream DoFn error, or shard/writer failure.","commonSituations":"Emitting values that cannot be coded by the output Coder (unexported fields, channels, funcs); downstream DoFn returning an error; worker-side I/O failures during GBK or sink writes.","solutions":["Read the wrapped error in the panic message to find the true downstream cause.","Ensure the emitted type has a registered/valid coder (avoid chan, func, unexported-only fields).","Handle expected errors inside the downstream DoFn instead of returning them, or validate elements before Emit.","Wrap Emit-heavy DoFns with error logging/recovery if partial failure semantics are desired."],"exampleFix":"// before\nfor _, v := range results {\n    emit(v) // panics if downstream fails\n}\n\n// after\nfor _, v := range results {\n    if err := validate(v); err != nil {\n        log.Printf(\"skipping invalid element: %v\", err)\n        continue\n    }\n    emit(v)\n}","handlingStrategy":"try-catch","validationCode":"// validate emitted values are codable before Emit\nif err := validateElement(v); err != nil { log and skip }","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        log.Printf(\"emit failed: %v\", r)\n        // abort bundle or mark failure\n    }\n}()","preventionTips":["Ensure emitted types have registered, valid coders (no chan/func fields).","Handle expected errors inside downstream DoFns rather than returning them.","Read the panic's wrapped error to target the actual failing stage."],"tags":["go","apache-beam","panic","emitter","dofn"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}