{"record":{"id":"0c639719d3d4f8d0","repo":"apache/beam","slug":"input-v-must-be-a-slice-or-array","errorCode":null,"errorMessage":"input %v must be a slice or array","messagePattern":"input (.+?) must be a slice or array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/teststream/teststream.go","lineNumber":148,"sourceCode":"\t\t}\n\t\tnewElements = append(newElements, &pipepb.TestStreamPayload_TimestampedElement{EncodedElement: buf.Bytes(), Timestamp: timestamp})\n\t}\n\taddElementsEvent := &pipepb.TestStreamPayload_Event_AddElements{Elements: newElements}\n\telementEvent := &pipepb.TestStreamPayload_Event_ElementEvent{ElementEvent: addElementsEvent}\n\tc.events = append(c.events, &pipepb.TestStreamPayload_Event{Event: elementEvent})\n\treturn nil\n}\n\n// AddElementList inserts a slice of elements into the stream at the specified event timestamp. Must be called with\n// at least one element.\n//\n// Calls into AddElements, which panics if an inserted type does not match a previously inserted element type.\n//\n// Element types must have built-in coders in Beam.\nfunc (c *Config) AddElementList(timestamp int64, elements any) error {\n\tval := reflect.ValueOf(elements)\n\tif val.Kind() != reflect.Slice && val.Kind() != reflect.Array {\n\t\treturn fmt.Errorf(\"input %v must be a slice or array\", elements)\n\t}\n\n\tvar inputs []any\n\tfor i := 0; i < val.Len(); i++ {\n\t\tinputs = append(inputs, val.Index(i).Interface())\n\t}\n\treturn c.AddElements(timestamp, inputs...)\n}\n\n// Create inserts a TestStream primitive into a pipeline, taking a scope and a Config object and\n// producing an output PCollection. The TestStream must be the first PTransform in the\n// pipeline.\nfunc Create(s beam.Scope, c Config) beam.PCollection {\n\tpyld := protox.MustEncode(c.createPayload())\n\toutputs := []beam.FullType{c.elmType}\n\n\toutput := beam.External(s, urn, pyld, []beam.PCollection{}, outputs, false)\n","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/teststream/teststream.go#L130-L166","documentation":"AddElementList accepts a single container argument of any type and expands it into elements. It requires the argument to be a Go slice or array; any other kind (map, string, scalar, nil) is rejected with this error.","triggerScenarios":"Calling Config.AddElementList(ts, x) where x is not a slice or array — e.g. a map, a single scalar value, or an untyped nil.","commonSituations":"Passing a single element instead of a list by mistake, passing a map when a slice of keys/values was intended, or passing a typed nil slice variable.","solutions":["Wrap the element in a slice: AddElementList(ts, []int{1,2}) instead of AddElementList(ts, 1)","Convert maps to slices before passing","Ensure the value is non-nil and a real slice/array type","Note: an empty non-nil slice is valid and adds no elements"],"exampleFix":"// before\ncfg.AddElementList(0, 42)\n// after\ncfg.AddElementList(0, []int{42})","handlingStrategy":"type-guard","validationCode":"v := reflect.ValueOf(elements)\nif v.Kind() != reflect.Slice && v.Kind() != reflect.Array { return fmt.Errorf(\"need slice/array, got %s\", v.Kind()) }","typeGuard":"func isSliceOrArray(v any) bool {\n    k := reflect.ValueOf(v).Kind()\n    return k == reflect.Slice || k == reflect.Array\n}","tryCatchPattern":"if err := cfg.AddElementList(ts, elems); err != nil {\n    t.Fatalf(\"AddElementList input must be a slice/array: %v\", err)\n}","preventionTips":["Always pass literal slices: []int{...}, []string{...}","Wrap single elements in a one-element slice","Convert maps to ordered slices before passing","Check for nil before calling"],"tags":["go","testing","teststream","argument-validation"],"backgroundTag":"invalid-argument-value","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"}