{"record":{"id":"0ba86d1970a7ccdb","repo":"apache/beam","slug":"splitrestriction-has-unexpected-number-of-return-values-v-0ba86d","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.tmpl","lineNumber":109,"sourceCode":"\t{{end}}\n{{end}}\n{{end}}\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{{range $out := upto 3}}\n{{range $in := upto 5}}\n    {{if gt $out 0}}\n    {{if gt $in 1}}\n\tcase reflectx.Func{{$in}}x{{$out}}:\n\t\tn.call = func() (size float64, err error) {\n\t\t\t{{mktuplef $out \"r%v\"}} := fnT.Call{{$in}}x{{$out}}({{mktuplef $in \"n.args[%v]\"}})","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl#L91-L127","documentation":"The SDF invoker requires SplitRestriction to return either 1 value (slice of restrictions) or 2 values (slice + error); other arities hit the panic fallback. This enforces the splittable DoFn method contract at invocation time.","triggerScenarios":"A DoFn's SplitRestriction returns 0 or 3+ values; the generated dispatcher has no case for that arity and panics during pipeline execution.","commonSituations":"Hand-written SDFs with incorrect SplitRestriction signatures; refactorings that changed return counts without updating the SDF contract.","solutions":["Make SplitRestriction return exactly ([]Restriction) or ([]Restriction, error)","Verify the signature against the Beam Go SDF documentation","Regenerate/check any code that wraps the DoFn so the arity matches"],"exampleFix":"// before\nfunc (fn *sdfFn) SplitRestriction(r Rest, n int) ([]Rest, int, error) { ... }\n\n// after\nfunc (fn *sdfFn) SplitRestriction(r Rest) ([]Rest, error) { ... }","handlingStrategy":"validation","validationCode":"m := reflect.ValueOf(fn).MethodByName(\"SplitRestriction\")\nif m.IsValid() && m.Type().NumOut() != 1 && m.Type().NumOut() != 2 {\n    return fmt.Errorf(\"SplitRestriction must return 1 or 2 values\")\n}","typeGuard":"func validSplitRestriction(fn interface{}) bool {\n    m := reflect.ValueOf(fn).MethodByName(\"SplitRestriction\")\n    if !m.IsValid() { return false }\n    n := m.Type().NumOut()\n    return n == 1 || n == 2\n}","tryCatchPattern":"defer func() {\n    if r := recover(); strings.Contains(fmt.Sprint(r), \"SplitRestriction has unexpected number of return values\") {\n        log.Fatalf(\"SDF signature error: %v\", r)\n    }\n}()","preventionTips":["Keep SplitRestriction returning ([]Restriction) or ([]Restriction, error)","Re-check signatures after refactoring SDFs","Use the beam SDF test harness (sdks/go/pkg/beam/sdf) to validate"],"tags":["go","apache-beam","sdf","arity","panic"],"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-14T16:17:12.679Z"}