apache/beam · error
value at index has type , want
Error message
value %v at index %v has type %v, want %v
What it means
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.
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
Example fix
// before
pc, err := beam.TryCreate(s, []any{1, "2", 3.0})
// after
pc, err := beam.TryCreate(s, []int{1, 2, 3}) Defensive patterns
Strategy: validation
Validate before calling
t := reflect.TypeOf(values[0])
for _, v := range values { if reflect.TypeOf(v) != t { return fmt.Errorf("element %v (%T) differs from %s", v, v, t) } } Type guard
func homogeneous[T any](vals []any) bool { for _, v := range vals { if _, ok := v.(T); !ok { return false } }; return true } Try / catch
pc, err := beam.TryCreate(s, values)
if err != nil {
if strings.Contains(err.Error(), "has type") { /* coerce all elements to a single type and retry */ }
return PCollection{}, err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- bad type: , want
- input must be a slice or array
- invalid pos type: %T
- Nested FullValues must be nested as pointers.
- passert.Diff input PColections don't have matching types
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/461f4fe8fa2134db.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/create.go:93
if len(ret) == 0 {
t = reflect.TypeOf(list).Elem()
} else {
t = reflect.ValueOf(ret[0]).Type()
}
return createList(s, ret, t)
}
func addCreateCtx(err error, s Scope) error {
return errors.WithContextf(err, "inserting Create in scope %s", s)
}
func createList(s Scope, values []any, t reflect.Type) (PCollection, error) {
fn := &createFn{Type: EncodedType{T: t}}
enc := NewElementEncoder(t)
for i, value := range values {
if other := reflect.ValueOf(value).Type(); other != t {
err := errors.Errorf("value %v at index %v has type %v, want %v", value, i, other, t)
return PCollection{}, addCreateCtx(err, s)
}
var buf bytes.Buffer
if err := enc.Encode(value, &buf); err != nil {
err = errors.Wrapf(err, "marshalling of %v failed", value)
return PCollection{}, addCreateCtx(err, s)
}
fn.Values = append(fn.Values, buf.Bytes())
}
imp := Impulse(s)
ret, err := TryParDo(s, fn, imp, TypeDefinition{Var: TType, T: t})
if err != nil || len(ret) != 1 {
panic(addCreateCtx(errors.WithContext(err, "internal error"), s))
}
return ret[0], nil
}View on GitHub (pinned to 12126d8942)