apache/beam · error
panic(err)
Error message
panic(err)
What it means
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.
Source
Thrown at sdks/go/pkg/beam/register/emitter.go:64
e.est = est
}
type emit1[T any] struct {
emit
n exec.ElementProcessor
}
func (e *emit1[T]) Value() any {
return e.invoke
}
func (e *emit1[T]) invoke(val T) {
e.value = exec.FullValue{Pane: e.pn, Windows: e.ws, Timestamp: e.et, Elm: val}
if e.est != nil {
(*e.est).(sdf.TimestampObservingEstimator).ObserveTimestamp(e.et.ToTime())
}
if err := e.n.ProcessElement(e.ctx, &e.value); err != nil {
panic(err)
}
}
type emit2[T1, T2 any] struct {
emit
n exec.ElementProcessor
}
func (e *emit2[T1, T2]) Value() any {
return e.invoke
}
func (e *emit2[T1, T2]) invoke(key T1, val T2) {
e.value = exec.FullValue{Pane: e.pn, Windows: e.ws, Timestamp: e.et, Elm: key, Elm2: val}
if e.est != nil {
(*e.est).(sdf.TimestampObservingEstimator).ObserveTimestamp(e.et.ToTime())
}
if err := e.n.ProcessElement(e.ctx, &e.value); err != nil {View on GitHub (pinned to 12126d8942)
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.
Example fix
// before
for _, v := range results {
emit(v) // panics if downstream fails
}
// after
for _, v := range results {
if err := validate(v); err != nil {
log.Printf("skipping invalid element: %v", err)
continue
}
emit(v)
} Defensive patterns
Strategy: try-catch
Validate before calling
// validate emitted values are codable before Emit
if err := validateElement(v); err != nil { log and skip } Try / catch
defer func() {
if r := recover(); r != nil {
log.Printf("emit failed: %v", r)
// abort bundle or mark failure
}
}() Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Unable to infer the types of StartBundle
- Invalid signature for StartBundle
- invoker: %v has > 5 return values, which is not permitted
- OnTimer function is defined for the DoFn but no TimerProvide
- OnTimer and ProcessElement functions for DoFn should have ex
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/19f646aad5619020.
Report an issue: GitHub.