{"record":{"id":"efd153f5e2ce94ec","repo":"apache/beam","slug":"unexpected-number-of-elements-returned-in-method-v-got-v","errorCode":null,"errorMessage":"unexpected number of elements returned in method %v. got: %v, want %v. Check that the signature conforms to the expected signature for %v.","messagePattern":"unexpected number of elements returned 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":1296,"sourceCode":"\t\t\t\t\tinitialWatermarkEstimatorStateName, 0, method.Param[0].T, typex.EventTimeType)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"mismatched event time type in method %v, \"+\n\t\t\t\t\t\"parameter at index %v. got: %v, want: %v.\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, 0, method.Param[0].T, typex.EventTimeType)\n\t\t\t}\n\t\t\tif method.Param[1].T != restT {\n\t\t\t\terr := errors.Errorf(\"mismatched restriction type in method %v, param %v. got: %v, want: %v\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, 1, method.Param[1].T, restT)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"mismatched restriction type in method %v, \"+\n\t\t\t\t\t\"parameter at index %v. got: %v, want: %v (from method %v). \"+\n\t\t\t\t\t\"Ensure that all restrictions in an SDF are the same type.\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, 1, method.Param[1].T, restT, createTrackerName)\n\t\t\t}\n\t\t\tif err := validateSdfElementT(fn, initialWatermarkEstimatorStateName, method, numMainIn, 2); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif len(method.Ret) != 1 {\n\t\t\t\terr := errors.Errorf(\"unexpected number of elements returned in method %v. got: %v, want %v\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, len(method.Ret), 1)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"unexpected number of elements returned in method %v. \"+\n\t\t\t\t\t\"got: %v, want %v. Check that the signature conforms to the expected signature for %v.\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, len(method.Ret), 1, initialWatermarkEstimatorStateName)\n\t\t\t}\n\t\t\tif method.Ret[0].T != watermarkStateT {\n\t\t\t\terr := errors.Errorf(\"mismatched output type in method %v, return %v. got: %v, want: %v\",\n\t\t\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"mismatched output type in method %v, \"+\n\t\t\t\t\t\"return value at index %v got: %v, want: %v (from method %v). \"+\n\t\t\t\t\t\"Ensure that all watermark states in an SDF are the same type.\",\n\t\t\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT, createWatermarkEstimatorName)\n\t\t\t}\n\t\tcase watermarkEstimatorStateName:\n\t\t\tif len(method.Param) != 1 {\n\t\t\t\terr := errors.Errorf(\"unexpected number of params in method %v. got: %v, want %v\",\n\t\t\t\t\twatermarkEstimatorStateName, len(method.Param), 1)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"unexpected number of parameters in method %v. \"+","sourceCodeStart":1278,"sourceCodeEnd":1314,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1278-L1314","documentation":"In a stateful SDF, WatermarkEstimatorState must return exactly one value: the current watermark state extracted from the estimator. Beam validates len(method.Ret) == 1 and throws this error when the method returns zero values or multiple return values (e.g. also returning an error, which this signature does not allow).","triggerScenarios":"Declaring WatermarkEstimatorState(we sdf.WatermarkEstimator) (myState, error) or with no return value; returning extra metadata alongside the state.","commonSituations":"Adding an error return out of Go habit since most other DoFn methods return errors; refactoring to also return the estimator; following a stateless SDF pattern in a stateful one.","solutions":["Change WatermarkEstimatorState to return exactly one value of the state type; handle errors inside or in RunWatermarkEstimator, which does return an error.","If you need to signal failure, return a zero-value/failed state or handle it in RunWatermarkEstimator.","Confirm you modified WatermarkEstimatorState and not another similarly named method.","Check the documented signature table for stateful SDF watermark methods."],"exampleFix":"// before\nfunc (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) (myState, error) {\n    s, err := extract(we)\n    return s, err\n}\n// after\nfunc (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) myState {\n    return we.(*myWatermarkEstimator).state\n}","handlingStrategy":"validation","validationCode":"var _ func(sdf.WatermarkEstimator) myState = (*fn).WatermarkEstimatorState","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember WatermarkEstimatorState returns a single value, no error.","Handle errors in RunWatermarkEstimator, which is the only watermark method returning error.","Use a function-signature assertion to lock the return arity."],"tags":["go","apache-beam","sdf","watermark-estimator","return-count"],"backgroundTag":"invalid-argument-value","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"}