apache/beam · error

unexpected number of return values in method

Error message

unexpected number of return values in method %v. got: %v, want: %v. Check that the signature conforms to the expected signature for %v.

What it means

CreateWatermarkEstimator must return exactly one value (returnNum, currently 1) that implements sdf.WatermarkEstimator. Beam raises this error when the method returns the wrong number of return values, e.g. zero, or multiple outputs including an error.

Solutions

  1. Make CreateWatermarkEstimator return exactly one value implementing sdf.WatermarkEstimator.
  2. Remove any error return; handle construction failures in the DoFn constructor instead.
  3. If the return type is wrong rather than the count, ensure it implements sdf.WatermarkEstimator (see the subsequent 'does not implement' check).

Example fix

// before
func (fn *f) CreateWatermarkEstimator(state StateT) (*myEstimator, error) {...}
// after
func (fn *f) CreateWatermarkEstimator(state StateT) *myEstimator {...}
Defensive patterns

Strategy: validation

Validate before calling

func wmCreatorReturnsOne(fn interface{}) error {
    m, ok := reflect.TypeOf(fn).MethodByName("CreateWatermarkEstimator")
    if ok {
        we := reflect.TypeOf((*sdf.WatermarkEstimator)(nil)).Elem()
        if m.Type.NumOut() != 1 || !m.Type.Out(0).Implements(we) {
            return errors.New("CreateWatermarkEstimator must return exactly one sdf.WatermarkEstimator")
        }
    }
    return nil
}

Prevention

When it happens

Trigger: Declaring CreateWatermarkEstimator with no return value or with extra returns like (estimator, error); detected when len(method.Ret) != returnNum in validateCreateWatermarkEstimator.

Common situations: Following Go conventions of returning (value, error) in Beam DoFn methods, which Beam signatures do not use here; forgetting the return entirely in a stub.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/aad5a8e966596d90. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/graph/fn.go:1207

		err := validateStatefulWatermarkSig(fn, numMainIn)
		if err != nil {
			return err
		}
	} else {
		if _, ok := fn.methods[initialWatermarkEstimatorStateName]; ok {
			err := errors.Errorf("stateful watermark estimation method %v is present, "+
				"but CreateWatermarkEstimator doesn't take in a state parameter.", initialWatermarkEstimatorStateName)
			return err
		}
		if _, ok := fn.methods[watermarkEstimatorStateName]; ok {
			err := errors.Errorf("stateful watermark estimation method %v is present, "+
				"but CreateWatermarkEstimator doesn't take in a state parameter.", watermarkEstimatorStateName)
			return err
		}
	}

	if len(method.Ret) != returnNum {
		err := errors.Errorf("unexpected number of returns in method %v. got: %v, want: %v",
			createWatermarkEstimatorName, len(method.Ret), returnNum)
		return errors.SetTopLevelMsgf(err, "unexpected number of return values in method %v. "+
			"got: %v, want: %v. Check that the signature conforms to the expected signature for %v.",
			createWatermarkEstimatorName, len(method.Ret), returnNum, createWatermarkEstimatorName)
	} else if !method.Ret[0].T.Implements(watermarkEstimatorT) {
		err := errors.Errorf("invalid output type in method %v, return %v: %v does not implement sdf.WatermarkEstimator",
			createWatermarkEstimatorName, 0, method.Ret[0].T)
		return errors.SetTopLevelMsgf(err, "invalid output type in method %v, "+
			"return value at index %v (type: %v). Output of method %v must implement sdf.WatermarkEstimator.",
			createWatermarkEstimatorName, 0, method.Ret[0].T, createWatermarkEstimatorName)
	}

	processFn := fn.methods[processElementName]
	pos, _ := processFn.WatermarkEstimator()
	if pos != -1 && method.Ret[0].T != processFn.Param[pos].T {
		err := errors.Errorf("mismatched output type in method %v, return %v: got: %v, want: %v",
			watermarkEstimatorStateName, 0, method.Ret[0].T, processFn.Param[pos].T)
		return errors.SetTopLevelMsgf(err, "Mismatched output type in method %v, "+

View on GitHub (pinned to 12126d8942)