apache/beam · error
unexpected number of parameters in method
Error message
unexpected number of parameters in method %v. got: %v, want %v. Check that the signature conforms to the expected signature for %v, and that elements in SDF method parameters match elements in %v.
What it means
In a stateful SDF, WatermarkEstimatorState must take exactly one parameter — the sdf.WatermarkEstimator whose state is being read. Beam validates len(method.Param) == 1 and throws this error when the method has zero parameters or extra ones (e.g. context or restriction), because the runner calls it with just the estimator.
Solutions
- Change WatermarkEstimatorState to take exactly one parameter of type sdf.WatermarkEstimator.
- Move any needed context or restriction access into the estimator itself (store it when created) or into other methods.
- Verify against the documented stateful SDF signature table.
- Check the method name — Beam matches by exact name, so a differently named method won't satisfy this check.
Example fix
// before
func (f *fn) WatermarkEstimatorState(ctx context.Context, we sdf.WatermarkEstimator) myState { ... }
// after
func (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) myState {
return we.(*myWatermarkEstimator).state
} Defensive patterns
Strategy: validation
Validate before calling
var _ func(sdf.WatermarkEstimator) myState = (*fn).WatermarkEstimatorState
Prevention
- WatermarkEstimatorState takes only the estimator — no context, no restriction.
- Store any needed context data in the estimator when it's created.
- Lock the signature with a compile-time assertion.
When it happens
Trigger: Declaring WatermarkEstimatorState(ctx context.Context, we sdf.WatermarkEstimator) or WatermarkEstimatorState(rest MyRestriction, we sdf.WatermarkEstimator); omitting the estimator parameter entirely.
Common situations: Adding context out of habit from other DoFn methods; copying ProcessElement's parameter style; misunderstanding which methods receive extra SDF parameters.
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
- unexpected number of parameters in method
- invalid output type in method
- mismatched event time type in method
- mismatched output type in method
- mismatched watermark state type in method
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/b07228cd9d45cab1.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:1312
if len(method.Ret) != 1 {
err := errors.Errorf("unexpected number of elements returned in method %v. got: %v, want %v",
initialWatermarkEstimatorStateName, len(method.Ret), 1)
return errors.SetTopLevelMsgf(err, "unexpected number of elements returned in method %v. "+
"got: %v, want %v. Check that the signature conforms to the expected signature for %v.",
initialWatermarkEstimatorStateName, len(method.Ret), 1, initialWatermarkEstimatorStateName)
}
if method.Ret[0].T != watermarkStateT {
err := errors.Errorf("mismatched output type in method %v, return %v. got: %v, want: %v",
createWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT)
return errors.SetTopLevelMsgf(err, "mismatched output type in method %v, "+
"return value at index %v got: %v, want: %v (from method %v). "+
"Ensure that all watermark states in an SDF are the same type.",
createWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT, createWatermarkEstimatorName)
}
case watermarkEstimatorStateName:
if len(method.Param) != 1 {
err := errors.Errorf("unexpected number of params in method %v. got: %v, want %v",
watermarkEstimatorStateName, len(method.Param), 1)
return errors.SetTopLevelMsgf(err, "unexpected number of parameters in method %v. "+
"got: %v, want %v. Check that the signature conforms to the expected signature for %v, "+
"and that elements in SDF method parameters match elements in %v.",
watermarkEstimatorStateName, len(method.Param), 1, watermarkEstimatorStateName, processElementName)
}
if method.Param[0].T != watermarkEstimatorT {
err := errors.Errorf("mismatched watermark state type in method %v, return %v. got: %v, want: %v",
watermarkEstimatorStateName, 0, method.Param[0].T, watermarkEstimatorT)
return errors.SetTopLevelMsgf(err, "mismatched watermark state type in method %v, "+
"return value at index %v got: %v, want: %v (from method %v). "+
"Ensure that all watermark states in an SDF are the same type.",
watermarkEstimatorStateName, 0, method.Param[0].T, watermarkEstimatorT, watermarkEstimatorStateName)
}
if len(method.Ret) != 1 {
err := errors.Errorf("unexpected number of elements returned in method %v. got: %v, want %v",
watermarkEstimatorStateName, len(method.Ret), 1)
return errors.SetTopLevelMsgf(err, "unexpected number of elements returned in method %v. "+View on GitHub (pinned to 12126d8942)