{"record":{"id":"fabfcaa6e58669b0","repo":"apache/beam","slug":"restrictionsize-has-unexpected-number-of-return-values-v","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.go","lineNumber":215,"sourceCode":"\t\t\treturn r0.(float64), 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(\"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\n\tcase reflectx.Func1x1:\n\t\tn.call = func() (rt sdf.RTracker, err error) {\n\t\t\tr0 := fnT.Call1x1(n.args[0])\n\t\t\treturn r0.(sdf.RTracker), nil\n\t\t}\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go#L197-L233","documentation":"The reflection invoker for the SDF method RestrictionSize requires the method to return a float64 size, optionally paired with an error. If the reflected invocation returns any other number of values, the runtime cannot extract the size and panics with this message. The float64 type assertion in the source shows the contract is strict about both arity and type.","triggerScenarios":"RestrictionSize returning int instead of float64 (type assertion failure path) or with 0/3+ returns; a method registered as RestrictionSize that actually computes something else.","commonSituations":"Using Go's natural int for sizes; updating the method to return a struct or percentage alongside the size; porting code from other SDKs (Python/Java) with different size conventions.","solutions":["Return exactly float64 (e.g. r.Size(elem) float64)","Optionally return (float64, error) — keep the size first","Cast internal size computations to float64 before returning","Re-verify with a unit test calling the invoker path"],"exampleFix":"// before\nfunc (fn *MyDoFn) RestrictionSize(r MyRestriction, elem string) int { return int(r.End - r.Start) }\n// after\nfunc (fn *MyDoFn) RestrictionSize(r MyRestriction, elem string) (float64, error) { return r.End - r.Start, nil }","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn.RestrictionSize)\nif t.NumOut() != 1 && t.NumOut() != 2 {\n    panic(\"RestrictionSize must return (float64) or (float64, error)\")\n}","typeGuard":"func validSizeOut(m interface{}) bool {\n    t := reflect.TypeOf(m)\n    return t.NumOut() >= 1 && t.Out(0).Kind() == reflect.Float64\n}","tryCatchPattern":null,"preventionTips":["Always use float64 for restriction sizes, never int","Cast computed sizes: return float64(r.End - r.Start)","Add a unit test invoking RestrictionSize through the invoker","Follow the sdf package's canonical RestrictionSize examples"],"tags":["go","apache-beam","splittable-dofn","type-mismatch"],"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"}