apache/beam · error
errIllegalParametersInEmit
Error message
errIllegalParametersInEmit
What it means
unfoldEmit validates emitter functions (func parameters used to emit output elements, e.g. func(string) in a DoFn). When one of the emitter's own parameters fails isInParam (not a universal/container type and typex.CheckConcrete rejects it), the error is wrapped as errIllegalParametersInEmit. Beam throws this because an emitter can only push values that are valid PCollection elements. Related hard rule in the same block: a bare interface{} (any) emitter parameter is rejected with "Type interface{}{} isn't a supported PCollection type".
Source
Thrown at sdks/go/pkg/beam/core/funcx/output.go:85
return nil, false, nil
}
if t.NumIn() == 0 {
return nil, false, nil
}
var ret []reflect.Type
skip := 0
if t.In(0) == typex.EventTimeType {
ret = append(ret, typex.EventTimeType)
skip = 1
}
if t.NumIn()-skip > 2 || t.NumIn() == skip {
return nil, false, nil
}
emptyInterface := reflect.TypeOf((*any)(nil)).Elem()
for i := skip; i < t.NumIn(); i++ {
if ok, err := isInParam(t.In(i)); !ok {
return nil, false, errors.Wrap(err, errIllegalParametersInEmit)
}
if ((t.In(i).Kind() == reflect.Ptr && t.In(i).Elem() == emptyInterface) || t.In(i) == emptyInterface) && !typex.IsUniversal(t.In(i)) {
return nil, false, errors.New("Type interface{} isn't a supported PCollection type")
}
ret = append(ret, t.In(i))
}
return ret, true, nil
}
func isInParam(t reflect.Type) (bool, error) {
if typex.IsUniversal(t) || typex.IsContainer(t) {
return true, nil
}
return typex.CheckConcrete(t)
}
View on GitHub (pinned to 12126d8942)
Solutions
- Change the emitter's parameter to a concrete PCollection element type (e.g. func(func(MyType) bool)).
- Replace interface{} (any) with a concrete type, or use typex.Universal types (typex.T, typex.KV, typex.WindowedValue) if truly generic emission is needed.
- Split map/struct emissions into concrete types or wrap them in typex.KV pairs.
- Sanity-check the emitter with funcx.UnfoldEmit(reflect.TypeOf(emitter)) in a test to see exactly which parameter is rejected.
Example fix
// before
func (f *fn) ProcessElement(s string, emit func(any)) { emit(s) }
// after
func (f *fn) ProcessElement(s string, emit func(string)) { emit(s) } Defensive patterns
Strategy: validation
Validate before calling
emitType := reflect.TypeOf(emit)
types, ok := funcx.UnfoldEmit(emitType)
if !ok {
return fmt.Errorf("not a valid emitter: %v", emitType)
}
for _, et := range types {
if et == reflect.TypeOf((*any)(nil)).Elem() {
return errors.New("emitter parameter interface{} is not a supported PCollection type")
}
} Type guard
func validEmitter(t reflect.Type) bool { _, ok := funcx.UnfoldEmit(t); return ok } Try / catch
if ok, err := funcx.IsMalformedEmit(reflect.TypeOf(emitField)); ok {
return fmt.Errorf("emit %v unusable: %w", reflect.TypeOf(emitField), err)
} Prevention
- Type emitters with concrete element types only; avoid any/interface{}
- Never emit maps, channels, or funcs directly
- Validate custom emit signatures with funcx.UnfoldEmit before wiring them into DoFns
When it happens
Trigger: Registering a DoFn whose emit function parameter takes an invalid input type: e.g. func(func(any) bool), func(func(chan int) bool), func(func(map[string]int) bool), or func(func(T) bool) where T fails typex.CheckConcrete. Surfaces through IsEmit/IsMalformedEmit/UnfoldEmit and then funcx.New during beam.ParDo.
Common situations: Trying to emit generic/any values from a DoFn; emitting maps or channels directly; generics-era refactors that turned element types into interface{}; emitting pointer-to-interface types that concrete-type checking rejects.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- bad return type for %s: %v
- may only have a single context.Context parameter and it must
- may only have a single PaneInfo parameter and it must preced
- may only have a single Window parameter and it must precede
- may only have a single beam.EventTime parameter and it must
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/32295a62c2522b07.
Report an issue: GitHub.