{"record":{"id":"aad5a8e966596d90","repo":"apache/beam","slug":"unexpected-number-of-return-values-in-method-v-got-v-want-v","errorCode":null,"errorMessage":"unexpected number of return values in method %v. got: %v, want: %v. Check that the signature conforms to the expected signature for %v.","messagePattern":"unexpected number of return values in method (.+?)\\. got: (.+?), want: (.+?)\\. Check that the signature conforms to the expected signature for (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":1207,"sourceCode":"\t\terr := validateStatefulWatermarkSig(fn, numMainIn)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\tif _, ok := fn.methods[initialWatermarkEstimatorStateName]; ok {\n\t\t\terr := errors.Errorf(\"stateful watermark estimation method %v is present, \"+\n\t\t\t\t\"but CreateWatermarkEstimator doesn't take in a state parameter.\", initialWatermarkEstimatorStateName)\n\t\t\treturn err\n\t\t}\n\t\tif _, ok := fn.methods[watermarkEstimatorStateName]; ok {\n\t\t\terr := errors.Errorf(\"stateful watermark estimation method %v is present, \"+\n\t\t\t\t\"but CreateWatermarkEstimator doesn't take in a state parameter.\", watermarkEstimatorStateName)\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif len(method.Ret) != returnNum {\n\t\terr := errors.Errorf(\"unexpected number of returns in method %v. got: %v, want: %v\",\n\t\t\tcreateWatermarkEstimatorName, len(method.Ret), returnNum)\n\t\treturn errors.SetTopLevelMsgf(err, \"unexpected number of return values in method %v. \"+\n\t\t\t\"got: %v, want: %v. Check that the signature conforms to the expected signature for %v.\",\n\t\t\tcreateWatermarkEstimatorName, len(method.Ret), returnNum, createWatermarkEstimatorName)\n\t} else if !method.Ret[0].T.Implements(watermarkEstimatorT) {\n\t\terr := errors.Errorf(\"invalid output type in method %v, return %v: %v does not implement sdf.WatermarkEstimator\",\n\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T)\n\t\treturn errors.SetTopLevelMsgf(err, \"invalid output type in method %v, \"+\n\t\t\t\"return value at index %v (type: %v). Output of method %v must implement sdf.WatermarkEstimator.\",\n\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T, createWatermarkEstimatorName)\n\t}\n\n\tprocessFn := fn.methods[processElementName]\n\tpos, _ := processFn.WatermarkEstimator()\n\tif pos != -1 && method.Ret[0].T != processFn.Param[pos].T {\n\t\terr := errors.Errorf(\"mismatched output type in method %v, return %v: got: %v, want: %v\",\n\t\t\twatermarkEstimatorStateName, 0, method.Ret[0].T, processFn.Param[pos].T)\n\t\treturn errors.SetTopLevelMsgf(err, \"Mismatched output type in method %v, \"+","sourceCodeStart":1189,"sourceCodeEnd":1225,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1189-L1225","documentation":"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.","triggerScenarios":"Declaring CreateWatermarkEstimator with no return value or with extra returns like (estimator, error); detected when len(method.Ret) != returnNum in validateCreateWatermarkEstimator.","commonSituations":"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.","solutions":["Make CreateWatermarkEstimator return exactly one value implementing sdf.WatermarkEstimator.","Remove any error return; handle construction failures in the DoFn constructor instead.","If the return type is wrong rather than the count, ensure it implements sdf.WatermarkEstimator (see the subsequent 'does not implement' check)."],"exampleFix":"// before\nfunc (fn *f) CreateWatermarkEstimator(state StateT) (*myEstimator, error) {...}\n// after\nfunc (fn *f) CreateWatermarkEstimator(state StateT) *myEstimator {...}","handlingStrategy":"validation","validationCode":"func wmCreatorReturnsOne(fn interface{}) error {\n    m, ok := reflect.TypeOf(fn).MethodByName(\"CreateWatermarkEstimator\")\n    if ok {\n        we := reflect.TypeOf((*sdf.WatermarkEstimator)(nil)).Elem()\n        if m.Type.NumOut() != 1 || !m.Type.Out(0).Implements(we) {\n            return errors.New(\"CreateWatermarkEstimator must return exactly one sdf.WatermarkEstimator\")\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Return exactly one value implementing sdf.WatermarkEstimator; never return (value, error).","Use concrete estimator types from the sdf package (e.g. sdf.NewTimestampedWatermarkEstimator).","Add a compile-time assertion: var _ sdf.WatermarkEstimator = (*myEstimator)(nil)."],"tags":["go","apache-beam","watermark","validation"],"backgroundTag":"invalid-return-count","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}