{"record":{"id":"08a9dae470ee4f10","repo":"apache/beam","slug":"restrictionsize-has-unexpected-number-of-return-values-v-sdf","errorCode":null,"errorMessage":"RestrictionSize has unexpected number of return values: %v","messagePattern":"RestrictionSize 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":153,"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(\"RestrictionSize has unexpected number of parameters: %v\", len(n.fn.Param))\n\t\t}\n\n\t\tn.call = func() (size float64, 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].(float64), nil\n\t\t\tcase 2:\n\t\t\t\treturn ret[0].(float64), asError(ret[1])\n\t\t\t}\n\n\t\t\tpanic(fmt.Sprintf(\"RestrictionSize has unexpected number of return values: %v\", len(ret)))\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (n *ctInvoker) initCallFn() error {\n\t// Expects a signature of the form:\n\t// (context.Context?, restriction) (sdf.RTracker, 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 3}}\n    {{if gt $out 0}}\n    {{if gt $in 0}}\n\tcase reflectx.Func{{$in}}x{{$out}}:\n\t\tn.call = func() (rt sdf.RTracker, err error) {\n\t\t\t{{mktuplef $out \"r%v\"}} := fnT.Call{{$in}}x{{$out}}({{mktuplef $in \"n.args[%v]\"}})","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl#L135-L171","documentation":"The SDF invoker requires RestrictionSize to return either 1 value (float64 size) or 2 values (size + error). Any other return count panics, since the generated dispatcher cannot map it. The size is cast to float64, so the first return must also be float64-compatible.","triggerScenarios":"A splittable DoFn whose RestrictionSize returns 0 or 3+ values (or whose first return is not a numeric float64), executed in a pipeline.","commonSituations":"Returning int size without float64; adding extra return values during refactoring; misunderstanding the SDF size-estimation contract.","solutions":["Make RestrictionSize return exactly (float64) or (float64, error)","Ensure the restriction type passed in matches the one produced by CreateInitialRestriction","Cross-check with Beam Go SDF examples in the docs"],"exampleFix":"// before\nfunc (fn *sdfFn) RestrictionSize(r Rest) (int, string, error) { ... }\n\n// after\nfunc (fn *sdfFn) RestrictionSize(r Rest) (float64, error) { ... }","handlingStrategy":"validation","validationCode":"m := reflect.ValueOf(fn).MethodByName(\"RestrictionSize\")\nif m.IsValid() {\n    t := m.Type()\n    if (t.NumOut() != 1 && t.NumOut() != 2) || t.Out(0).Kind() != reflect.Float64 {\n        return fmt.Errorf(\"RestrictionSize must return float64 (plus optional error)\")\n    }\n}","typeGuard":"func validRestrictionSize(fn interface{}) bool {\n    m := reflect.ValueOf(fn).MethodByName(\"RestrictionSize\")\n    if !m.IsValid() { return false }\n    t := m.Type()\n    return (t.NumOut() == 1 || t.NumOut() == 2) && t.Out(0).Kind() == reflect.Float64\n}","tryCatchPattern":"defer func() {\n    if r := recover(); strings.Contains(fmt.Sprint(r), \"RestrictionSize has unexpected number of return values\") {\n        log.Fatalf(\"SDF signature error: %v\", r)\n    }\n}()","preventionTips":["Always return float64 (never int) from RestrictionSize","Return (float64) or (float64, error) only","Match the restriction type used in CreateInitialRestriction"],"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-14T21:17:11.552Z"}