{"record":{"id":"310be809a13d4276","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-310be8","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 5 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1131,"sourceCode":"}\n\nfunc (c *shimFunc5x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc5x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc5x1) Call5x1(arg0, arg1, arg2, arg3, arg4 any) any {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc5x1(c Func) Func5x1 {\n\tif c.Type().NumIn() != 5 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func5x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc5x1{inner: c}\n}\n\nfunc MakeFunc5x1(fn any) Func5x1 {\n\treturn ToFunc5x1(MakeFunc(fn))\n}\n\ntype Func5x2 interface {\n\tFunc\n\tCall5x2(any, any, any, any, any) (any, any)\n}\n\ntype shimFunc5x2 struct {\n\tinner Func","sourceCodeStart":1113,"sourceCodeEnd":1149,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L1113-L1149","documentation":"reflectx.ToFunc5x1 wraps a reflectx.Func into a Func5x1 (5 inputs, 1 output). It panics with this message when the func's reflect.Type does not have exactly 5 inputs and 1 output. The check exists so the shim can safely unpack the single return value.","triggerScenarios":"Calling reflectx.ToFunc5x1(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 1. Commonly a map-style function with 5 inputs returning 2 values (element + error) or returning nothing.","commonSituations":"Beam DoFns whose ProcessElement returns (T, error) instead of a single value; arity drift after adding an input parameter; using ToFunc5x1 where the pipeline registered a 5x2 signature.","solutions":["Adjust the function to take 5 inputs and return exactly 1 value (drop the error return or fold it in).","Use ToFunc5x2 (or the matching variant) if the function legitimately returns 2 values.","Re-check the expected signature in the calling Beam registration code and align the function to it."],"exampleFix":"// before\nfunc fn(a A, b B, c C, d D, e E) (T, error) { ... }\nreflectx.ToFunc5x1(fn) // panics: 2 outputs\n\n// after\nfunc fn(a A, b B, c C, d D, e E) T { ... }\nreflectx.ToFunc5x1(fn)","handlingStrategy":"validation","validationCode":"fn := reflect.TypeOf(fnAny)\nif fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 1 {\n    _ = reflectx.ToFunc5x1(fnAny)\n}","typeGuard":"func isFunc5x1(f interface{}) bool {\n    t := reflect.TypeOf(f)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 1\n}","tryCatchPattern":"func safeToFunc5x1(c reflectx.Func) (f reflectx.Func5x1, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"ToFunc5x1 failed: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc5x1(c), nil\n}","preventionTips":["Remember (T, error) counts as 2 outputs — use ToFunc5x2 or drop the error.","Recount inputs after adding context/event-time/emit parameters.","Test wrapping of user functions in CI before launching pipelines.","Match ToFunc helper names to signatures explicitly in code review."],"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"}