{"record":{"id":"621031701ebe01e3","repo":"apache/beam","slug":"create-has-no-values","errorCode":null,"errorMessage":"create has no values","messagePattern":"create has no values","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/create.go","lineNumber":51,"sourceCode":"//\n// The returned PCollections can be used as any other PCollections. The values\n// are JSON-coded. Each runner may place limits on the sizes of the values and\n// Create should generally only be used for small collections.\nfunc Create(s Scope, values ...any) PCollection {\n\treturn Must(TryCreate(s, values...))\n}\n\n// CreateList inserts a fixed set of values into the pipeline from a slice or\n// array. Unlike Create this supports the creation of an empty PCollection.\nfunc CreateList(s Scope, list any) PCollection {\n\treturn Must(TryCreateList(s, list))\n}\n\n// TryCreate inserts a fixed non-empty set of values into the pipeline. The\n// values must be of the same type.\nfunc TryCreate(s Scope, values ...any) (PCollection, error) {\n\tif len(values) == 0 {\n\t\terr := errors.New(\"create has no values\")\n\t\treturn PCollection{}, addCreateCtx(err, s)\n\t}\n\n\tt := reflect.ValueOf(values[0]).Type()\n\treturn createList(s, values, t)\n}\n\n// TryCreateList inserts a fixed set of values into the pipeline from a slice or\n// array. The values must be of the same type. Unlike TryCreate this supports\n// the creation of an empty PCollection.\nfunc TryCreateList(s Scope, list any) (PCollection, error) {\n\tval := reflect.ValueOf(list)\n\tif val.Kind() != reflect.Slice && val.Kind() != reflect.Array {\n\t\terr := errors.Errorf(\"input %v must be a slice or array\", list)\n\t\treturn PCollection{}, addCreateCtx(err, s)\n\t}\n\n\tvar ret []any","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/create.go#L33-L69","documentation":"TryCreate requires a non-empty set of values to insert into the pipeline as a PCollection. Called with zero values, it fails with 'create has no values', wrapped with the scope context by addCreateCtx.","triggerScenarios":"Calling beam.Create (which delegates to TryCreate) with no variadic arguments, or a slice expanded with `values...` where the slice is empty.","commonSituations":"Expanding an empty slice into Create: `beam.Create(s, items...)` when items is empty; data-driven code paths where a default set of values was expected but config produced none.","solutions":["Guard that the value slice is non-empty before calling beam.Create","Supply a default/fallback value set when input is empty","If an empty collection is valid, build it via a different mechanism (e.g. Create with a sentinel then Filter, or a side input) since Create cannot be empty","Handle the returned error and skip the transform when there is nothing to create"],"exampleFix":"// before\npc := beam.Create(s, items...) // panics/error if len(items)==0\n// after\nif len(items) == 0 {\n    items = []string{\"\"} // or handle empty case explicitly\n}\npc := beam.Create(s, items...)","handlingStrategy":"validation","validationCode":"if len(values) == 0 {\n    return errors.New(\"beam.Create requires at least one value\")\n}\npc := beam.Create(s, values...)","typeGuard":null,"tryCatchPattern":"pc, err := beam.TryCreate(s, values...)\nif err != nil {\n    if strings.Contains(err.Error(), \"create has no values\") { return handleEmptyInput() }\n    return err\n}","preventionTips":["Never expand unchecked slices into beam.Create","Prefer beam.TryCreate in library code to get an error instead of a hard failure","Decide policy for empty inputs (default values vs skip transform)","Add unit tests for empty-input paths"],"tags":["go","apache-beam","pipeline-construction"],"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"}