apache/beam · error
emit parameters expected in method
Error message
emit parameters expected in method %v
What it means
validateEmits checks that if ProcessElement declares emit parameters, every other emitting method (StartBundle, FinishBundle) declares the same ones — and vice versa. When the method has no emits but ProcessElement does, this error fires with a message explaining emits must be consistent across methods.
Solutions
- Add the same emit func parameter(s) to StartBundle/FinishBundle that ProcessElement declares
- Or, if the method should not emit, remove mismatched expectations and keep emission in ProcessElement only
- Keep emit signatures identical (type and order) across all emitting methods
Example fix
// before
func (f *MyFn) StartBundle(ctx context.Context) error { f.emitLater() ... }
func (f *MyFn) ProcessElement(s string, emit func(int)) error { ... }
// after
func (f *MyFn) StartBundle(ctx context.Context, emit func(int)) error { ... } Defensive patterns
Strategy: validation
Validate before calling
// if ProcessElement has emit funcs, StartBundle/FinishBundle must declare identical ones
pe, _ := reflect.TypeOf(fn).MethodByName("ProcessElement")
sb, hasSb := reflect.TypeOf(fn).MethodByName("StartBundle")
if hasSb && emitCount(pe.Type) > 0 && emitCount(sb.Type) == 0 {
return errors.New("StartBundle must declare the same emit parameters as ProcessElement")
} Prevention
- Keep emit func signatures identical across ProcessElement, StartBundle, FinishBundle
- Review DoFn signatures after adding or removing emit parameters
When it happens
Trigger: Declaring ProcessElement(s string, emit func(int)) but StartBundle/FinishBundle without the matching emit func parameter, or declaring a method expected to emit with zero emit parameters while ProcessElement has them.
Common situations: Emitting from StartBundle/FinishBundle (e.g. flushing state) but forgetting to add the emit parameter to those methods; refactoring ProcessElement to add an emit without updating StartBundle.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Duplicate state key used by and . Ensure that state keys…
- emit parameter in method
- error writing state
- failed to find method
- invalid DoFn
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/820626396dc43e1a.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:704
}
return nil
}
// validateEmits compares the emits found in a DoFn method signature with the emits found in
// the signature for ProcessElement, and performs validation that those match. This function
// should only be used to validate methods that are expected to have the same emit parameters as
// ProcessElement.
func validateEmits(processFnEmits []funcx.FnParam, method *funcx.Fn, methodName string) error {
posMethodEmits, numMethodEmits, ok := method.Emits()
numProcessEmits := len(processFnEmits)
// Handle cases where method has no emits.
if !ok {
if numProcessEmits == 0 { // We're good, expected no emits.
return nil
}
// Error, missing emits.
err := errors.Errorf("emit parameters expected in method %v", methodName)
return errors.SetTopLevelMsgf(err,
"Missing emit parameters in the %v method of a DoFn. "+
"If emit parameters are present in %v those parameters must also be present in %v.",
methodName, processElementName, methodName)
}
// Error if number of emits doesn't match.
if numMethodEmits != numProcessEmits {
err := errors.Errorf("number of emits in method %v does not match method %v: got %d, expected %d",
methodName, processElementName, numMethodEmits, numProcessEmits)
return errors.SetTopLevelMsgf(err,
"Incorrect number of emit parameters in the %v method of a DoFn. "+
"The emit parameters should match those of the %v method.",
methodName, processElementName)
}
// Error if there's a type mismatch.
methodEmits := method.Param[posMethodEmits : posMethodEmits+numMethodEmits]View on GitHub (pinned to 12126d8942)