{"record":{"id":"7f4444222a946dc6","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-7f4444","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 3 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 4 inputs and 3 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1008,"sourceCode":"}\n\nfunc (c *shimFunc4x3) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc4x3) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc4x3) Call4x3(arg0, arg1, arg2, arg3 any) (any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2]\n}\n\nfunc ToFunc4x3(c Func) Func4x3 {\n\tif c.Type().NumIn() != 4 || c.Type().NumOut() != 3 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 3 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func4x3); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc4x3{inner: c}\n}\n\nfunc MakeFunc4x3(fn any) Func4x3 {\n\treturn ToFunc4x3(MakeFunc(fn))\n}\n\ntype Func4x4 interface {\n\tFunc\n\tCall4x4(any, any, any, any) (any, any, any, any)\n}\n\ntype shimFunc4x4 struct {\n\tinner Func","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L990-L1026","documentation":"reflectx.ToFunc4x3 converts a generic Func to a strongly-typed Func4x3 (4 inputs, 3 outputs). The converter asserts the underlying reflect.Type has exactly NumIn()==4 and NumOut()==3 and panics otherwise. The Beam Go SDK fails fast here so the shim's fixed three-value return unpacking cannot index past the end of a shorter return slice at pipeline runtime.","triggerScenarios":"Calling reflectx.ToFunc4x3(f) where f.Type().NumIn() != 4 (e.g. 3 or 5 params) or f.Type().NumOut() != 3 (e.g. 2 or 4 return values).","commonSituations":"Multi-output functions extended with an extra return during a schema change (4 outputs), trimmed to 2 outputs, or given a wrong converter name after copy-paste; functions where an added emitter parameter pushed inputs to 5.","solutions":["Adjust the function to take exactly 4 parameters and return exactly 3 values.","Switch to the converter matching the real shape (ToFunc4x2 or ToFunc4x4).","Confirm in/out counts with reflect.TypeOf(fn) before wrapping.","Where the signature is unstable, register via Beam's higher-level APIs so signature checking is centralized rather than hand-picked converters."],"exampleFix":"// before\nf := reflectx.ToFunc4x3(func(a int, b, c string, d bool) (int, string, bool, error) { return a, b, c, nil }) // 4 outputs, panics\n// after\nf := reflectx.ToFunc4x3(func(a int, b, c string, d bool) (int, string, error) { return a, b, nil })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 4 || t.NumOut() != 3 {\n    panic(fmt.Sprintf(\"expected 4-in/3-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc4x3(f)","typeGuard":"func isFunc4x3(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 4 && t.NumOut() == 3\n}","tryCatchPattern":"func safeToFunc4x3(f reflectx.Func) (out reflectx.Func4x3, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc4x3: %v\", r) } }()\n    out = reflectx.ToFunc4x3(f)\n    return\n}","preventionTips":["Re-check arity after any refactor that adds or removes a return value.","Add table-driven tests asserting reflect type arity per converter.","Keep the ToFuncNxM call on the line directly above the function literal so diffs surface mismatches.","Treat a panic from reflectx as a build-time bug: recover at registration boundaries and fail the test suite, not the running pipeline."],"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"}