{"record":{"id":"50523aa030bae97e","repo":"apache/beam","slug":"createinitialrestriction-has-unexpected-number-of-return","errorCode":null,"errorMessage":"CreateInitialRestriction has unexpected number of return values: %v","messagePattern":"CreateInitialRestriction has unexpected number of return values: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go","lineNumber":87,"sourceCode":"\t\t\treturn r0, asError(r1)\n\t\t}\n\n\tdefault:\n\t\tif len(n.fn.Param) < 1 || len(n.fn.Param) > 3 {\n\t\t\treturn errors.Errorf(\"CreateInitialRestriction has unexpected number of parameters: %v\", len(n.fn.Param))\n\t\t}\n\n\t\tn.call = func() (rest any, err error) {\n\t\t\tret := n.fn.Fn.Call(n.args)\n\n\t\t\tswitch len(ret) {\n\t\t\tcase 1:\n\t\t\t\treturn ret[0], nil\n\t\t\tcase 2:\n\t\t\t\treturn ret[0], asError(ret[1])\n\t\t\t}\n\n\t\t\tpanic(fmt.Sprintf(\"CreateInitialRestriction has unexpected number of return values: %v\", len(ret)))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (n *srInvoker) initCallFn() error {\n\t// Expects a signature of the form:\n\t// (context.Context?, key?, value, restriction) ([]restriction, error?)\n\t// TODO(BEAM-9643): Link to full documentation.\n\tswitch fnT := n.fn.Fn.(type) {\n\n\tcase reflectx.Func2x1:\n\t\tn.call = func() (splits any, err error) {\n\t\t\tr0 := fnT.Call2x1(n.args[0], n.args[1])\n\t\t\treturn r0, nil\n\t\t}\n","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go#L69-L105","documentation":"The Beam Go SDK's reflection-based invoker for the splittable DoFn (SDF) method CreateInitialRestriction validates the signature's return arity at call time. A valid DoFn must return either just the restriction, or (restriction, error). Any other number of return values triggers this panic, because the runtime cannot map the reflection results onto the expected contract.","triggerScenarios":"Defining a DoFn method CreateInitialRestriction with 0, or 3+ return values; wrong method wiring where the reflected call returns a mismatched result set (e.g. signature registered against the wrong method type).","commonSituations":"Hand-writing SDF methods instead of following the documented signatures; copy-paste refactors that changed return types; mixing up CreateInitialRestriction with a different SDF lifecycle method's signature.","solutions":["Change CreateInitialRestriction to return exactly one value: the restriction (e.g. (MyRestriction))","Or return two values: (MyRestriction, error) if the method can fail","Check the sdf package docs for the exact permitted signatures for your element type","Run the pipeline's local (direct) validation/tests before submitting to a runner"],"exampleFix":"// before\nfunc (fn *MyDoFn) CreateInitialRestriction(elem string) (MyRestriction, int, error) { ... }\n// after\nfunc (fn *MyDoFn) CreateInitialRestriction(elem string) MyRestriction { ... }","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn.CreateInitialRestriction)\nif t.NumOut() != 1 && t.NumOut() != 2 {\n    panic(\"CreateInitialRestriction must return (R) or (R, error)\")\n}","typeGuard":"func validArity(m interface{}) bool {\n    n := reflect.TypeOf(m).NumOut()\n    return n == 1 || n == 2\n}","tryCatchPattern":null,"preventionTips":["Copy signatures verbatim from the sdf package docs/examples","Add compile-time interface assertions for your DoFn","Run DoFn signature validation tests locally before submitting pipelines","Never add extra return values for logging/diagnostics to SDF lifecycle methods"],"tags":["go","apache-beam","splittable-dofn","reflection"],"backgroundTag":"invalid-argument-format","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"}