{"record":{"id":"4ac0a03e9270ebdc","repo":"apache/beam","slug":"input-v-must-be-a-slice-or-array-create","errorCode":null,"errorMessage":"input %v must be a slice or array","messagePattern":"input (.+?) must be a slice or array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/create.go","lineNumber":65,"sourceCode":"// 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\n\tfor i := 0; i < val.Len(); i++ {\n\t\tret = append(ret, val.Index(i).Interface())\n\t}\n\n\tvar t reflect.Type\n\tif len(ret) == 0 {\n\t\tt = reflect.TypeOf(list).Elem()\n\t} else {\n\t\tt = reflect.ValueOf(ret[0]).Type()\n\t}\n\treturn createList(s, ret, t)\n}\n\nfunc addCreateCtx(err error, s Scope) error {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/create.go#L47-L83","documentation":"TryCreateList inserts a fixed set of values from a Go slice or array into the pipeline. This error is thrown when the input value's reflect.Kind is neither Slice nor Array — there is no element sequence to turn into a PCollection.","triggerScenarios":"Calling CreateList/TryCreateList with a map, string, struct, pointer, or nil instead of a slice/array.","commonSituations":"Passing a single element instead of a slice of elements, passing a map where a slice was intended, or a config value unmarshalled into any/interface{} as a non-slice type.","solutions":["Wrap the input in a slice: CreateList(s, []int{1,2,3}) instead of CreateList(s, 1)","If passing a map, extract its values into a slice first","Use TryCreate instead if you intend to create a PCollection of a single value"],"exampleFix":"// before\npc, err := beam.TryCreateList(s, 42)\n// after\npc, err := beam.TryCreateList(s, []int{42})","handlingStrategy":"validation","validationCode":"v := reflect.ValueOf(list)\nif v.Kind() != reflect.Slice && v.Kind() != reflect.Array { return fmt.Errorf(\"%T is not a slice/array\", list) }","typeGuard":"func isSliceOrArray(v any) bool { k := reflect.ValueOf(v).Kind(); return k == reflect.Slice || k == reflect.Array }","tryCatchPattern":"pc, err := beam.TryCreateList(s, list)\nif err != nil {\n    if strings.Contains(err.Error(), \"must be a slice or array\") { /* wrap single value in a 1-element slice */ }\n    return PCollection{}, err\n}","preventionTips":["Always pass typed slices (e.g. []int{...}) rather than bare values or []any of mixed types","Check whether beam.Create/beam.CreateList matches your intent before calling","Guard config-driven values with a kind check before creating PCollections"],"tags":["beam","type-mismatch","go"],"backgroundTag":"incompatible-source-type","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"}