{"record":{"id":"61b6228be886c731","repo":"apache/beam","slug":"createinitialrestriction-has-unexpected-number-of-return-sdf","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.tmpl","lineNumber":65,"sourceCode":"\t{{end}}\n{{end}}\n{{end}}\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{{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() (splits any, err error) {\n\t\t\t{{mktuplef $out \"r%v\"}} := fnT.Call{{$in}}x{{$out}}({{mktuplef $in \"n.args[%v]\"}})","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl#L47-L83","documentation":"Beam's SDF invoker (sdf_invokers_arity.tmpl) validates that a user's CreateInitialRestriction method returns 1 value (the restriction) or 2 values (restriction + error). Any other return arity cannot be dispatched and panics at runtime. This guards user DoFn signatures for splittable DoFns.","triggerScenarios":"Defining a splittable DoFn whose CreateInitialRestriction returns 0 or 3+ values, then executing a pipeline with that SDF.","commonSituations":"Misremembering the SDF method contract; copy-paste refactor leaving extra return values; mixing up CreateInitialRestriction with other method signatures.","solutions":["Change CreateInitialRestriction to return exactly (Restriction) or (Restriction, error)","Check the Beam Go SDF docs for the required method signatures","If the signature looks correct, ensure you are on a Beam version matching your DoFn's registration code"],"exampleFix":"// before\nfunc (fn *sdfFn) CreateInitialRestriction(r Range) (Rest, Extra, error) { ... }\n\n// after\nfunc (fn *sdfFn) CreateInitialRestriction(r Range) (Rest, error) { ... }","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn).Method(0) // or MethodByName(\"CreateInitialRestriction\")\nif t.Type.NumOut() != 1 && t.Type.NumOut() != 2 {\n    return fmt.Errorf(\"CreateInitialRestriction must return 1 or 2 values\")\n}","typeGuard":"func validCreateInitialRestriction(fn interface{}) bool {\n    m := reflect.ValueOf(fn).MethodByName(\"CreateInitialRestriction\")\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), \"CreateInitialRestriction has unexpected number of return values\") {\n        log.Fatalf(\"SDF signature error: %v\", r)\n    }\n}()","preventionTips":["Follow the documented SDF method signatures exactly","Return (restriction) or (restriction, error) — nothing else","Test SDFs with a small local pipeline before submitting to a runner"],"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"}