{"record":{"id":"293fa2dcc17f1266","repo":"apache/beam","slug":"emit-parameter-in-method-v-does-not-match-emit-parameter-in","errorCode":null,"errorMessage":"emit parameter in method %v does not match emit parameter in %v","messagePattern":"emit parameter in method (.+?) does not match emit parameter in (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":726,"sourceCode":"\t\t\tmethodName, processElementName, methodName)\n\t}\n\n\t// Error if number of emits doesn't match.\n\tif numMethodEmits != numProcessEmits {\n\t\terr := errors.Errorf(\"number of emits in method %v does not match method %v: got %d, expected %d\",\n\t\t\tmethodName, processElementName, numMethodEmits, numProcessEmits)\n\t\treturn errors.SetTopLevelMsgf(err,\n\t\t\t\"Incorrect number of emit parameters in the %v method of a DoFn. \"+\n\t\t\t\t\"The emit parameters should match those of the %v method.\",\n\t\t\tmethodName, processElementName)\n\t}\n\n\t// Error if there's a type mismatch.\n\tmethodEmits := method.Param[posMethodEmits : posMethodEmits+numMethodEmits]\n\tfor i := 0; i < numProcessEmits; i++ {\n\t\tif processFnEmits[i].T != methodEmits[i].T {\n\t\t\tvar err error = &funcx.TypeMismatchError{Got: methodEmits[i].T, Want: processFnEmits[i].T}\n\t\t\terr = errors.Wrapf(err, \"emit parameter in method %v does not match emit parameter in %v\",\n\t\t\t\tmethodName, processElementName)\n\t\t\treturn errors.SetTopLevelMsgf(err,\n\t\t\t\t\"Incorrect emit parameters in the %v method of a DoFn. \"+\n\t\t\t\t\t\"The emit parameters should match those of the %v method.\",\n\t\t\t\tmethodName, processElementName)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// validateSideInputs compares the inputs found in a DoFn method signature with the inputs found\n// in the signature for ProcessElement, and performs validation to check that the side inputs\n// match. This function should only be used to validate methods that are expected to have matching\n// side inputs to ProcessElement.\nfunc validateSideInputs(processFnInputs []funcx.FnParam, method *funcx.Fn, methodName string, numMainIn mainInputs) error {\n\tif numMainIn == MainUnknown {\n\t\treturn validateSideInputsNumUnknown(processFnInputs, method, methodName)","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L708-L744","documentation":"When a DoFn auxiliary method's emit parameters match ProcessElement's emit count, validateEmits also checks each emit parameter's type. If the i-th emit type in the method differs from the i-th emit type in ProcessElement, a funcx.TypeMismatchError is wrapped with this message and thrown from AsDoFn during graph construction.","triggerScenarios":"Declaring e.g. ProcessElement with emit func(int) but FinishBundle with emit func(string) (or an emit wrapped differently, like func(beam.X) vs func(int)), then converting the DoFn via AsDoFn / beam.ParDo.","commonSituations":"Changing an output element type in ProcessElement without updating auxiliary methods; using similar-looking emitter signatures on different element types; generics or custom emitter types that don't match the ProcessElement emitters exactly.","solutions":["Change the auxiliary method's emit parameter types to exactly match the corresponding ProcessElement emit types in order.","Verify order matters: the i-th emit in the auxiliary method must match the i-th emit in ProcessElement.","Use identical emitter function types (copy the signature from ProcessElement)."],"exampleFix":"// before\nfunc (fn *myFn) ProcessElement(w string, emit func(int)) {}\nfunc (fn *myFn) StartBundle(emit func(string)) {}\n\n// after\nfunc (fn *myFn) ProcessElement(w string, emit func(int)) {}\nfunc (fn *myFn) StartBundle(emit func(int)) {}","handlingStrategy":"validation","validationCode":"// ensure emitter types are declared once and reused:\ntype emitFn = func(int)\n// ProcessElement(w string, emit emitFn) and auxiliary methods use emitFn too","typeGuard":"func sameEmitType(a, b reflect.Type) bool { return a == b }","tryCatchPattern":"defer func() { if r := recover(); r != nil { log.Fatalf(\"emit type mismatch: %v\", r) } }()\n// or check returned error from pipeline build:\nif err := p.Run(); err != nil { /* signature errors surface here */ }","preventionTips":["Define emitter signatures as named types and reuse them in every method","When changing an output type, grep the DoFn for all emit parameters and update all","Keep emit parameter order identical to ProcessElement in auxiliary methods"],"tags":["go","apache-beam","dofn","type-mismatch","signature-validation"],"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"}