{"record":{"id":"bb5fa80653819165","repo":"apache/beam","slug":"truncaterestriction-has-unexpected-number-of-parameters-v-bb5fa8","errorCode":null,"errorMessage":"TruncateRestriction has unexpected number of parameters: %v","messagePattern":"TruncateRestriction has unexpected number of parameters: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl","lineNumber":228,"sourceCode":"{{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() (rest any, err error) {\n\t\t\t{{mktuplef $out \"r%v\"}} := fnT.Call{{$in}}x{{$out}}({{mktuplef $in \"n.args[%v]\"}})\n\t\t\t{{- if eq $out 1}}\n\t\t\treturn r0, nil\n\t\t\t{{- else}}\n\t\t\treturn r0, asError(r1)\n\t\t\t{{- end}}\n\t\t}\n\t{{end}}\n\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}","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.tmpl#L210-L246","documentation":"This panic comes from the generated SDF invoker code in the Beam Go SDK. A splittable DoFn's TruncateRestriction method must take between 2 and 4 parameters (restriction, element, optional context, optional rest of restriction); anything outside that range cannot be invoked by the generated arity-dispatch code, so the runtime panics.","triggerScenarios":"Defining TruncateRestriction with 0, 1, or 5+ parameters on a splittable DoFn and running the pipeline, causing the default branch of the generated dispatcher to reject the signature.","commonSituations":"Adding or removing parameters when porting TruncateRestriction between DoFns; hand-writing an SDF with an unusual signature; framework version differences in accepted arities.","solutions":["Adjust TruncateRestriction to accept 2-4 parameters, e.g. (restriction, element) optionally plus context/rest params","Consult the SDF truncation API contract in your SDK version and match an accepted signature","If truncation is not needed, remove the method rather than providing a malformed one"],"exampleFix":"// before\nfunc (fn *mySDF) TruncateRestriction() myRestriction { ... }\n// after\nfunc (fn *mySDF) TruncateRestriction(rest myRestriction, elem myElem) myRestriction { ... }","handlingStrategy":"validation","validationCode":"m, ok := reflect.TypeOf(fn).MethodByName(\"TruncateRestriction\")\nif ok {\n\tin := m.Type.NumIn()\n\tif in < 3 || in > 5 { // receiver + 2-4 params\n\t\treturn errors.New(\"TruncateRestriction must take 2-4 parameters\")\n\t}\n}","typeGuard":"func validTruncateRestriction(fn interface{}) bool {\n\tm, ok := reflect.TypeOf(fn).MethodByName(\"TruncateRestriction\")\n\treturn !ok || (m.Type.NumIn() >= 3 && m.Type.NumIn() <= 5)\n}","tryCatchPattern":null,"preventionTips":["Match TruncateRestriction signatures from the official SDF docs exactly","Validate DoFn structure with unit tests using the SDK's DoFn testers","Avoid gratuitous extra parameters; use struct fields for extra state"],"tags":["go","apache-beam","splittable-dofn","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-20T03:17:13.778Z"}