{"record":{"id":"01292ace951518af","repo":"apache/beam","slug":"v-method-has-too-few-main-inputs","errorCode":null,"errorMessage":"%v method has too few main inputs","messagePattern":"(.+?) method has too few main inputs","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":668,"sourceCode":"\n// validateMainInputs checks that a method has the given number of main inputs\n// and that main inputs are before any side inputs.\nfunc validateMainInputs(fn *Fn, method *funcx.Fn, methodName string, numMainIn mainInputs) error {\n\tif numMainIn == MainUnknown {\n\t\tnumMainIn = MainSingle // If unknown, validate for minimum number of inputs.\n\t}\n\n\t// Make sure there are enough inputs (at least numMainIn)\n\tpos, num, ok := method.Inputs()\n\tif !ok {\n\t\terr := errors.Errorf(\"%v method has no main inputs\", methodName)\n\t\terr = errors.SetTopLevelMsgf(err,\n\t\t\t\"Method %v in DoFn %v is missing all inputs. A main input is required.\",\n\t\t\tmethodName, fn.Name())\n\t\treturn err\n\t}\n\tif num < int(numMainIn) {\n\t\terr := errors.Errorf(\"%v method has too few main inputs\", methodName)\n\t\terr = errors.SetTopLevelMsgf(err,\n\t\t\t\"Method %v in DoFn %v does not have enough main inputs. \"+\n\t\t\t\t\"%v main inputs were expected, but only %v inputs were found.\",\n\t\t\tmethodName, fn.Name(), numMainIn, num)\n\t\treturn err\n\t}\n\n\t// Check that the first input is not an Iter or ReIter (those aren't valid\n\t// as the first main input).\n\tfirst := method.Param[pos].Kind\n\tif first != funcx.FnValue {\n\t\terr := errors.New(\"first main input parameter must be a value type\")\n\t\terr = errors.SetTopLevelMsgf(err,\n\t\t\t\"Method %v of DoFns should always have the first input be a value type, \"+\n\t\t\t\t\"but it has an Iter or ReIter first in DoFn %v.\",\n\t\t\tprocessElementName, fn.Name())\n\t\treturn errors.WithContextf(err, \"method %v\", processElementName)\n\t}","sourceCodeStart":650,"sourceCodeEnd":686,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L650-L686","documentation":"validateMainInputs also enforces a minimum main-input count (numMainIn, default MainSingle). When ProcessElement declares fewer main inputs than required (e.g. zero or one where two are expected for KV inputs), this error is raised with a detailed top-level message.","triggerScenarios":"Using a DoFn with numMainIn > 1 (e.g. MainKVs) but declaring ProcessElement with a single element parameter; or dropping one of two parameters for a keyed PCollection.","commonSituations":"Applying a KV-expecting DoFn to key/value side-input patterns; changing PCollection element type from KV to single value without updating ProcessElement.","solutions":["Declare the required number of main input parameters (e.g. k, v for KVs)","Ensure numMainIn passed to NewDoFn/AsDoFn options matches the method signature","Check that the incoming PCollection type matches what the method expects"],"exampleFix":"// before\nfunc (f *MyFn) ProcessElement(ctx context.Context, k string, emit func(int)) error // expects KV\n// after\nfunc (f *MyFn) ProcessElement(ctx context.Context, k string, v int, emit func(int)) error","handlingStrategy":"validation","validationCode":"// ensure ProcessElement's main-input count matches the incoming PCollection shape (KV => 2 params)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match ProcessElement parameters to the PCollection coders (KV adds a key parameter)","Set numMainIn option only when intentionally handling multi-input DoFns"],"tags":["go","apache-beam","dofn","process-element"],"backgroundTag":"missing-required-argument","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"}