{"record":{"id":"7f3ff8fb6aac202d","repo":"apache/beam","slug":"no-input-pcollections","errorCode":null,"errorMessage":"no input pcollections","messagePattern":"no input pcollections","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/flatten.go","lineNumber":47,"sourceCode":"// of the first PCollection.\nfunc Flatten(s Scope, cols ...PCollection) PCollection {\n\treturn Must(TryFlatten(s, cols...))\n}\n\n// TryFlatten merges incoming PCollections of type 'A' to a single PCollection\n// of type 'A'. Returns an error indicating the set of PCollections that could\n// not be flattened.\nfunc TryFlatten(s Scope, cols ...PCollection) (PCollection, error) {\n\tif !s.IsValid() {\n\t\treturn PCollection{}, errors.New(\"invalid scope\")\n\t}\n\tfor i, in := range cols {\n\t\tif !in.IsValid() {\n\t\t\treturn PCollection{}, errors.Errorf(\"invalid pcollection to flatten: index %v\", i)\n\t\t}\n\t}\n\tif len(cols) == 0 {\n\t\treturn PCollection{}, errors.New(\"no input pcollections\")\n\t}\n\tif len(cols) == 1 {\n\t\treturn cols[0], nil // no-op\n\t}\n\n\tvar in []*graph.Node\n\tfor _, s := range cols {\n\t\tin = append(in, s.n)\n\t}\n\tedge, err := graph.NewFlatten(s.real, s.scope, in)\n\tif err != nil {\n\t\treturn PCollection{}, err\n\t}\n\tret := PCollection{edge.Output[0].To}\n\tret.SetCoder(cols[0].Coder())\n\treturn ret, nil\n}\n","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/flatten.go#L29-L65","documentation":"TryFlatten requires at least one input PCollection to merge; calling it with zero PCollections makes the flatten transform meaningless (nothing to produce), so the library rejects the call with this error. Note the check runs after the per-collection validity loop, so collections must also be valid.","triggerScenarios":"beam.Flatten(s) or beam.TryFlatten(s) called with an empty variadic list — typically when the inputs are gathered programmatically (e.g. appending to a slice under conditions that all evaluated false) and the slice is empty at call time.","commonSituations":"Building a list of PCollections from optional/conditional pipeline branches where every branch was skipped; refactoring that removed all inputs but kept the Flatten call; passing a filtered slice without checking its length.","solutions":["Guard the call: only invoke Flatten when len(cols) > 0; if the slice is empty, skip the flatten and use/propagate the (empty) inputs appropriately.","If logically there is exactly one input, call it directly — TryFlatten already no-ops for len==1, so a single element is fine, zero is not.","Log the input collection list before the call to find why all candidates were filtered out."],"exampleFix":"// before\nmerged := beam.Flatten(s, cols...) // panics/errors when cols is empty\n\n// after\nvar merged beam.PCollection\nswitch {\ncase len(cols) == 0:\n\t// handle empty case, e.g. skip flatten or return an error\ndefault:\n\tmerged = beam.Flatten(s, cols...)\n}","handlingStrategy":"validation","validationCode":"if len(cols) == 0 {\n\treturn fmt.Errorf(\"no pcollections to flatten\")\n}\nout := beam.Flatten(s, cols...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check len() on any dynamically built slice of PCollections before expanding with '...'.","Decide semantics for the empty-input case (skip merge vs error) in your pipeline builder.","Remember Flatten with exactly 1 input is a no-op — only 0 is an error."],"tags":["go","apache-beam","flatten","empty-input"],"backgroundTag":"empty-required-field","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"}