{"record":{"id":"5451242584b1cb5f","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-545124","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 4 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":926,"sourceCode":"}\n\nfunc (c *shimFunc4x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc4x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc4x1) Call4x1(arg0, arg1, arg2, arg3 any) any {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc4x1(c Func) Func4x1 {\n\tif c.Type().NumIn() != 4 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func4x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc4x1{inner: c}\n}\n\nfunc MakeFunc4x1(fn any) Func4x1 {\n\treturn ToFunc4x1(MakeFunc(fn))\n}\n\ntype Func4x2 interface {\n\tFunc\n\tCall4x2(any, any, any, any) (any, any)\n}\n\ntype shimFunc4x2 struct {\n\tinner Func","sourceCodeStart":908,"sourceCodeEnd":944,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L908-L944","documentation":"reflectx.ToFunc4x1 converts a generic Func to a strongly-typed Func4x1 (4 inputs, 1 output). The converter verifies the underlying reflect.Type has exactly NumIn()==4 and NumOut()==1 and panics otherwise. The Beam SDK fails fast because the shim reads exactly one return value via reflection; an arity mismatch would corrupt results or crash the runner.","triggerScenarios":"Calling reflectx.ToFunc4x1(f) where f.Type().NumIn() != 4 (e.g. 3 or 5 params) or f.Type().NumOut() != 1 (no returns, or 2+ returns like (T, error)).","commonSituations":"Mapping functions that also emit an error (2 outputs), functions missing a parameter after an API change, or selecting the wrong converter for a function that returns (value, bool) — which counts as 2 outputs.","solutions":["Change the function to take exactly 4 parameters and return exactly 1 value.","For (value, error) or (value, bool) shapes use ToFunc4x2; for no returns use ToFunc4x0.","Verify with reflect.TypeOf(fn).NumIn()/NumOut() before wrapping.","If the 4th parameter is unnecessary, close over it instead of declaring it, reducing NumIn to 3 and matching a different converter."],"exampleFix":"// before\nf := reflectx.ToFunc4x1(func(a int, b, c string, d bool) (int, error) { return a, nil }) // 2 outputs, panics\n// after\nf := reflectx.ToFunc4x2(func(a int, b, c string, d bool) (int, error) { return a, nil })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 4 || t.NumOut() != 1 {\n    panic(fmt.Sprintf(\"expected 4-in/1-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc4x1(f)","typeGuard":"func isFunc4x1(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 4 && t.NumOut() == 1\n}","tryCatchPattern":"func safeToFunc4x1(f reflectx.Func) (out reflectx.Func4x1, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc4x1: %v\", r) } }()\n    out = reflectx.ToFunc4x1(f)\n    return\n}","preventionTips":["Use ToFunc4x2 when the mapper also returns an error or status flag.","Assert reflect arity in tests before registration.","Keep function signatures stable; prefer editing the function body over the signature.","Pair each signature change with the matching converter rename in code review."],"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-20T03:17:13.778Z"}