{"record":{"id":"4337dfc1836bd0cd","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-4337df","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 1 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":311,"sourceCode":"}\n\nfunc (c *shimFunc1x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc1x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc1x1) Call1x1(arg0 any) any {\n\tret := c.inner.Call([]any{arg0})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc1x1(c Func) Func1x1 {\n\tif c.Type().NumIn() != 1 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func1x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc1x1{inner: c}\n}\n\nfunc MakeFunc1x1(fn any) Func1x1 {\n\treturn ToFunc1x1(MakeFunc(fn))\n}\n\ntype Func1x2 interface {\n\tFunc\n\tCall1x2(any) (any, any)\n}\n\ntype shimFunc1x2 struct {\n\tinner Func","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L293-L329","documentation":"ToFunc1x1 adapts a generic reflectx Func into a Func1x1 (1 input, 1 output, a mapping function). It panics when the wrapped function's type does not have exactly 1 input and 1 output. This eager check prevents late failures during pipeline execution.","triggerScenarios":"Calling reflectx.ToFunc1x1 (or MakeFunc1x1, or beam coders' makeDecoder/makeEncoder, or makePartitionFn) with a Func whose Type().NumIn() != 1 or Type().NumOut() != 1.","commonSituations":"Defining a coder's encode/decode function with an extra error return; a partition function returning an int plus error; refactoring a map function to take a context parameter.","solutions":["Adjust the wrapped function to take exactly 1 argument and return exactly 1 value.","Use the matching ToFunc/MakeFuncNxM variant for the actual arity.","Check the signature against the expected Func1x1 shape before wrapping."],"exampleFix":"// before\nreflectx.MakeFunc1x1(func(b []byte) (int, error) { ... }) // panics: 2 outputs\n// after\nreflectx.MakeFunc1x1(func(b []byte) int { ... })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 1 || t.NumOut() != 1 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc1x1 needs 1 in/1 out\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc1x1(c reflectx.Func) bool {\n    return c.Type().NumIn() == 1 && c.Type().NumOut() == 1\n}","tryCatchPattern":"func safeToFunc1x1(c reflectx.Func) (f reflectx.Func1x1) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc1x1 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc1x1(c)\n}","preventionTips":["For coders, remember makeDecoder/makeEncoder expect exactly 1-in/1-out functions; drop error returns.","Test coder registration at init time so mismatches fail in tests, not mid-pipeline.","Keep one canonical mapping function per type and reuse it."],"tags":["go","reflection","arity-mismatch","panic"],"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"}