{"record":{"id":"7bcdd7b3882ef885","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-7bcdd7","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 3 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":721,"sourceCode":"}\n\nfunc (c *shimFunc3x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc3x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc3x1) Call3x1(arg0, arg1, arg2 any) any {\n\tret := c.inner.Call([]any{arg0, arg1, arg2})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc3x1(c Func) Func3x1 {\n\tif c.Type().NumIn() != 3 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func3x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc3x1{inner: c}\n}\n\nfunc MakeFunc3x1(fn any) Func3x1 {\n\treturn ToFunc3x1(MakeFunc(fn))\n}\n\ntype Func3x2 interface {\n\tFunc\n\tCall3x2(any, any, any) (any, any)\n}\n\ntype shimFunc3x2 struct {\n\tinner Func","sourceCodeStart":703,"sourceCodeEnd":739,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L703-L739","documentation":"reflectx.ToFunc3x1 converts a generic Func to a strongly-typed Func3x1 (3 inputs, 1 output). The converter validates the underlying reflect.Type has exactly NumIn()==3 and NumOut()==1 and panics otherwise. Beam throws this to fail fast at conversion time, since a mismatched arity would break the reflection-based invocation inside the pipeline runner.","triggerScenarios":"Calling reflectx.ToFunc3x1(f) where f.Type().NumIn() != 3 (e.g. 2 or 4 params) or f.Type().NumOut() != 1 (0 returns, or 2+ returns like (T, error)).","commonSituations":"A mapping function that gained an extra emitted output during refactoring (now 2 returns), a function missing an emitter/context parameter, or developers accidentally invoking the wrong ToFuncNxM for a function returning (T, error) which counts as 2 outputs.","solutions":["Adjust the wrapped function to take exactly 3 parameters and return exactly 1 value.","If it returns (value, error), that is 2 outputs — use ToFunc3x2 instead.","If it returns nothing, use ToFunc3x0.","Inspect reflect.TypeOf(fn) to confirm the actual in/out counts before choosing the converter."],"exampleFix":"// before\nf := reflectx.ToFunc3x1(func(a int, b string, c bool) (int, error) { return a, nil }) // 2 outputs, panics\n// after\nf := reflectx.ToFunc3x2(func(a int, b string, c bool) (int, error) { return a, nil })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 3 || t.NumOut() != 1 {\n    panic(fmt.Sprintf(\"expected 3-in/1-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc3x1(f)","typeGuard":"func isFunc3x1(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 3 && t.NumOut() == 1\n}","tryCatchPattern":"func safeToFunc3x1(f reflectx.Func) (out reflectx.Func3x1, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc3x1: %v\", r) } }()\n    out = reflectx.ToFunc3x1(f)\n    return\n}","preventionTips":["Match converter name to exact arity: (T, error) is 2 outputs, use ToFunc3x2.","Add a compile-adjacent assertion test for NumIn/NumOut on registered functions.","Update the converter call in the same commit as any signature change.","Prefer typed DoFn registration to avoid manual arity bookkeeping."],"tags":["go","apache-beam","reflection","panic","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-14T16:17:12.679Z"}