{"record":{"id":"461f4fe8fa2134db","repo":"apache/beam","slug":"value-v-at-index-v-has-type-v-want-v","errorCode":null,"errorMessage":"value %v at index %v has type %v, want %v","messagePattern":"value (.+?) at index (.+?) has type (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/create.go","lineNumber":93,"sourceCode":"\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 {\n\treturn errors.WithContextf(err, \"inserting Create in scope %s\", s)\n}\n\nfunc createList(s Scope, values []any, t reflect.Type) (PCollection, error) {\n\tfn := &createFn{Type: EncodedType{T: t}}\n\tenc := NewElementEncoder(t)\n\n\tfor i, value := range values {\n\t\tif other := reflect.ValueOf(value).Type(); other != t {\n\t\t\terr := errors.Errorf(\"value %v at index %v has type %v, want %v\", value, i, other, t)\n\t\t\treturn PCollection{}, addCreateCtx(err, s)\n\t\t}\n\t\tvar buf bytes.Buffer\n\t\tif err := enc.Encode(value, &buf); err != nil {\n\t\t\terr = errors.Wrapf(err, \"marshalling of %v failed\", value)\n\t\t\treturn PCollection{}, addCreateCtx(err, s)\n\t\t}\n\t\tfn.Values = append(fn.Values, buf.Bytes())\n\t}\n\n\timp := Impulse(s)\n\n\tret, err := TryParDo(s, fn, imp, TypeDefinition{Var: TType, T: t})\n\tif err != nil || len(ret) != 1 {\n\t\tpanic(addCreateCtx(errors.WithContext(err, \"internal error\"), s))\n\t}\n\treturn ret[0], nil\n}","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/create.go#L75-L111","documentation":"createList encodes each value for the Create PCollection using the declared element type t. This error is thrown when any individual element's concrete reflect type differs from t — all values in the list must share the exact same type.","triggerScenarios":"Calling beam.Create/TryCreate with a mixed-type []any, e.g. []any{1, \"two\"}, or elements whose dynamic type differs from the inferred/declared element type.","commonSituations":"Building test fixtures from heterogeneous literals, JSON-decoded data where numbers became float64 while other values are int, or accidentally including a nil element in the list.","solutions":["Make all elements the same concrete type (e.g. wrap everything as strings, or all as int)","Declare the values as a typed slice (e.g. []int{...}) instead of []any","Convert outliers before creating: float64(x) or fmt.Sprintf as appropriate"],"exampleFix":"// before\npc, err := beam.TryCreate(s, []any{1, \"2\", 3.0})\n// after\npc, err := beam.TryCreate(s, []int{1, 2, 3})","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(values[0])\nfor _, v := range values { if reflect.TypeOf(v) != t { return fmt.Errorf(\"element %v (%T) differs from %s\", v, v, t) } }","typeGuard":"func homogeneous[T any](vals []any) bool { for _, v := range vals { if _, ok := v.(T); !ok { return false } }; return true }","tryCatchPattern":"pc, err := beam.TryCreate(s, values)\nif err != nil {\n    if strings.Contains(err.Error(), \"has type\") { /* coerce all elements to a single type and retry */ }\n    return PCollection{}, err\n}","preventionTips":["Use typed slices instead of []any at call sites","Beware JSON-decoded any values becoming float64; normalize numeric types first","Watch for nil elements, which have a different (invalid) reflect type"],"tags":["beam","type-mismatch","go"],"backgroundTag":"type-mismatch","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"}