{"record":{"id":"40e143b168941871","repo":"apache/beam","slug":"truncaterestriction-has-unexpected-number-of-return-values-v","errorCode":null,"errorMessage":"TruncateRestriction has unexpected number of return values: %v","messagePattern":"TruncateRestriction 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":331,"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(\"TruncateRestriction 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(\"TruncateRestriction has unexpected number of return values: %v\", len(ret)))\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":313,"sourceCodeEnd":337,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go#L313-L337","documentation":"The reflection invoker for the SDF method TruncateRestriction expects either (truncatedRestriction) or (truncatedRestriction, error) return values. Any other arity causes this panic. Truncation is used for drain scenarios, so the contract violation is caught when the runtime invokes the method.","triggerScenarios":"TruncateRestriction defined with 0 or 3+ return values; returning (restriction, err, log message) or similar extra outputs; method registered under the wrong reflection key.","commonSituations":"Implementing drain support for the first time and guessing the signature; copying from a non-Beam truncation helper; refactors that added a return value for diagnostics.","solutions":["Return exactly the truncated restriction, e.g. (MyRestriction)","Or (MyRestriction, error) if truncation can fail","Match the restriction type to the one produced by CreateInitialRestriction","Verify signatures against the sdf package's documented lifecycle methods"],"exampleFix":"// before\nfunc (fn *MyDoFn) TruncateRestriction(r MyRestriction) (MyRestriction, string, error) { ... }\n// after\nfunc (fn *MyDoFn) TruncateRestriction(r MyRestriction) (MyRestriction, error) { ... }","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn.TruncateRestriction)\nif t.NumOut() != 1 && t.NumOut() != 2 {\n    panic(\"TruncateRestriction 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":["Keep the truncated restriction type identical to the initial restriction type","Mirror the signature style of your other SDF methods","Validate with drain-mode tests before production","Only add (…, error) when truncation can genuinely fail"],"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"}