{"record":{"id":"8380e6f7e09fb7fb","repo":"apache/beam","slug":"truncaterestriction-has-unexpected-number-of-return-values-v-8380e6","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.tmpl","lineNumber":241,"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(\"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":223,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl#L223-L247","documentation":"The SDF invoker requires TruncateRestriction to return either 1 value (the truncated restriction) or 2 values (restriction + error). Other arities hit the panic fallback in the generated dispatcher. This method is optional for SDFs but must follow the arity contract when present.","triggerScenarios":"Implementing TruncateRestriction with 0 or 3+ return values on a splittable DoFn and running a pipeline where truncation (e.g., drain) is invoked.","commonSituations":"Draining a streaming pipeline with a malformed TruncateRestriction; refactoring the method and changing its return count.","solutions":["Make TruncateRestriction return exactly (Rest) or (Rest, error)","If truncation isn't needed, remove the method entirely (it's optional) rather than keep a wrong signature","Validate the signature against Beam SDF documentation"],"exampleFix":"// before\nfunc (fn *sdfFn) TruncateRestriction(r Rest, b bool) (Rest, bool, error) { ... }\n\n// after\nfunc (fn *sdfFn) TruncateRestriction(r Rest) (Rest, error) { ... }","handlingStrategy":"validation","validationCode":"m := reflect.ValueOf(fn).MethodByName(\"TruncateRestriction\")\nif m.IsValid() && m.Type().NumOut() != 1 && m.Type().NumOut() != 2 {\n    return fmt.Errorf(\"TruncateRestriction must return 1 or 2 values\")\n}","typeGuard":"func validTruncateRestriction(fn interface{}) bool {\n    m := reflect.ValueOf(fn).MethodByName(\"TruncateRestriction\")\n    if !m.IsValid() { return true } // optional method\n    n := m.Type().NumOut()\n    return n == 1 || n == 2\n}","tryCatchPattern":"defer func() {\n    if r := recover(); strings.Contains(fmt.Sprint(r), \"TruncateRestriction has unexpected number of return values\") {\n        log.Fatalf(\"SDF signature error: %v\", r)\n    }\n}()","preventionTips":["Return (rest) or (rest, error) — nothing else","Remove the method if truncation support isn't needed","Test drain behavior on a small streaming pipeline before production"],"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"}