{"record":{"id":"a185511e35fcc314","repo":"apache/beam","slug":"splitrestriction-has-unexpected-number-of-return-values-v","errorCode":null,"errorMessage":"SplitRestriction has unexpected number of return values: %v","messagePattern":"SplitRestriction 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":151,"sourceCode":"\t\t\treturn r0, asError(r1)\n\t\t}\n\n\tdefault:\n\t\tif len(n.fn.Param) < 2 || len(n.fn.Param) > 4 {\n\t\t\treturn errors.Errorf(\"SplitRestriction has unexpected number of parameters: %v\", len(n.fn.Param))\n\t\t}\n\n\t\tn.call = func() (splits 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(\"SplitRestriction has unexpected number of return values: %v\", len(ret)))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (n *rsInvoker) initCallFn() error {\n\t// Expects a signature of the form:\n\t// (context.Context?, key?, value, restriction) (float64, 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() (size float64, err error) {\n\t\t\tr0 := fnT.Call2x1(n.args[0], n.args[1])\n\t\t\treturn r0.(float64), nil\n\t\t}\n","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go#L133-L169","documentation":"The reflection invoker for the SDF method SplitRestriction expects the user method to return either (split restrictions...) as a single slice/value, or that plus an error. When the reflected call yields a return-value count the invoker does not recognize, it panics with this message. It is a signature-contract violation detected at pipeline construction/execution time.","triggerScenarios":"Implementing SplitRestriction with 0 or 3+ return values; returning (restrictions, somethingElse, error); reflection wiring mismatch caused by wrong method registration.","commonSituations":"Custom splitting logic hand-written with extra outputs; refactors that added a return value without updating the invoker contract; copying signatures from non-SDF DoFn examples.","solutions":["Make SplitRestriction return exactly one value: the restriction slice (e.g. []MyRestriction)","Or two values: ([]MyRestriction, error)","Cross-check against the sdk splittable DoFn examples in sdks/go/pkg/beam/sdf","Validate the DoFn with the direct runner tests before production"],"exampleFix":"// before\nfunc (fn *MyDoFn) SplitRestriction(r MyRestriction, elem string) ([]MyRestriction, int, error) { ... }\n// after\nfunc (fn *MyDoFn) SplitRestriction(elem string, r MyRestriction) ([]MyRestriction, error) { ... }","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn.SplitRestriction)\nif t.NumOut() != 1 && t.NumOut() != 2 {\n    panic(\"SplitRestriction 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":["Return the restriction slice as the sole (or first) output","Keep SDF lifecycle methods minimal — no extra diagnostics outputs","Validate signatures with the direct runner before production","Consult beam splittable DoFn examples when implementing drain/truncate"],"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"}