{"record":{"id":"49a78a431ee85050","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-49a78a","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 2 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 5 inputs and 2 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1172,"sourceCode":"}\n\nfunc (c *shimFunc5x2) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc5x2) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc5x2) Call5x2(arg0, arg1, arg2, arg3, arg4 any) (any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})\n\t_ = ret\n\treturn ret[0], ret[1]\n}\n\nfunc ToFunc5x2(c Func) Func5x2 {\n\tif c.Type().NumIn() != 5 || c.Type().NumOut() != 2 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 2 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func5x2); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc5x2{inner: c}\n}\n\nfunc MakeFunc5x2(fn any) Func5x2 {\n\treturn ToFunc5x2(MakeFunc(fn))\n}\n\ntype Func5x3 interface {\n\tFunc\n\tCall5x3(any, any, any, any, any) (any, any, any)\n}\n\ntype shimFunc5x3 struct {\n\tinner Func","sourceCodeStart":1154,"sourceCodeEnd":1190,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L1154-L1190","documentation":"reflectx.ToFunc5x2 wraps a reflectx.Func into a Func5x2 (5 inputs, 2 outputs). It panics with this message if the func's reflect.Type does not have exactly 5 inputs and 2 outputs, since the shim returns ret[0], ret[1] directly.","triggerScenarios":"Calling reflectx.ToFunc5x2(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 2, e.g. a function returning a single value plus error vs two emitted values, or with a different input count.","commonSituations":"FlatMap-style DoFns returning (T, error) where a 5x2 (two emitted values) registration is required; signature changes during refactors; mismatch between emitted-value count and ToFunc helper chosen.","solutions":["Change the function to return exactly 2 values from 5 inputs.","Pick the correct ToFuncN x M helper for the actual signature (e.g. ToFunc5x1 for (T, error)).","If inputs are wrong (e.g. missing context or event-time), adjust the parameter list to 5 parameters."],"exampleFix":"// before\nfunc fn(a A, b B, c C, d D, e E) (T, error) { ... }\nreflectx.ToFunc5x2(fn) // panics: 2 outputs but semantically T+error; or 3 outputs\n\n// after\nfunc fn(a A, b B, c C, d D, e E) (T, U) { ... }\nreflectx.ToFunc5x2(fn)","handlingStrategy":"validation","validationCode":"fn := reflect.TypeOf(fnAny)\nif fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 2 {\n    _ = reflectx.ToFunc5x2(fnAny)\n}","typeGuard":"func isFunc5x2(f interface{}) bool {\n    t := reflect.TypeOf(f)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 2\n}","tryCatchPattern":"func safeToFunc5x2(c reflectx.Func) (f reflectx.Func5x2, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"ToFunc5x2 failed: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc5x2(c), nil\n}","preventionTips":["Decide up front whether outputs are emitted values or (value, error) and pick the helper accordingly.","Update the NxM registration helper whenever a function's return tuple changes.","Cover each registered DoFn with a wrap test.","Avoid copy-pasting registration lines without checking arity."],"tags":["go","apache-beam","reflection","function-signature"],"backgroundTag":"type-mismatch","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"}