apache/beam · error
unable to encode type
Error message
unable to encode type: %v
What it means
The RowEncoderBuilder cannot build a reflective encoder for the given Go type: its kind is not in the supported set for Beam schema row encoding. Same family as the decoder counterpart but on the encode path.
Solutions
- Restrict element types to schema-encodable kinds (primitives, strings, bytes, slices, maps, arrays, structs)
- Provide a custom coder via beam.EncodedCustomCoder or register a schema creator/type
- Strip or transform unsupported fields before encoding
Example fix
// before
type Point struct { Mutex sync.Mutex }
// after
type Point struct { X, Y float64 } Defensive patterns
Strategy: validation
Validate before calling
func encodable(t reflect.Type) bool {
switch t.Kind() {
case reflect.Chan, reflect.Func, reflect.Interface, reflect.UnsafePointer:
return false
}
return true
} Type guard
func isRowEncodable(v any) bool { return encodable(reflect.TypeOf(v)) } Try / catch
if _, err := (coder.RowEncoderBuilder{}).Build(t); err != nil {
return fmt.Errorf("type %T not row-encodable: %w", v, err)
} Prevention
- Test round-trip encoding of every element type in CI
- Keep element structs free of mutexes, channels, and funcs
- Fall back to custom coders for exotic types
When it happens
Trigger: Calling EncoderForSlice / encoderForStructReflect / containerEncoderForType on a type whose kind (e.g. chan, func, unsafe.Pointer, nested unsupported element) has no encoder case.
Common situations: A PCollection element struct contains an unsupported field type and the user relies on default schema coding.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/14345e9d8900a654.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/graph/coder/row_encoder.go:260
return typeEncoderFieldReflect{encode: iterableEncoder(t, encf)}, nil
case reflect.Array:
encf, err := b.containerEncoderForType(t.Elem())
if err != nil {
return typeEncoderFieldReflect{}, err
}
return typeEncoderFieldReflect{encode: iterableEncoder(t, encf)}, nil
case reflect.Map:
encK, err := b.containerEncoderForType(t.Key())
if err != nil {
return typeEncoderFieldReflect{}, err
}
encV, err := b.containerEncoderForType(t.Elem())
if err != nil {
return typeEncoderFieldReflect{}, err
}
return typeEncoderFieldReflect{encode: mapEncoder(t, encK, encV)}, nil
}
return typeEncoderFieldReflect{}, errors.Errorf("unable to encode type: %v", t)
}
func (b *RowEncoderBuilder) containerEncoderForType(t reflect.Type) (typeEncoderFieldReflect, error) {
encf, err := b.encoderForSingleTypeReflect(t)
if err != nil {
return typeEncoderFieldReflect{}, err
}
if t.Kind() == reflect.Ptr {
return typeEncoderFieldReflect{encode: NullableEncoder(encf.encode), addr: encf.addr}, nil
}
return encf, nil
}
type typeEncoderReflect struct {
debug []string
fields []typeEncoderFieldReflect
}
View on GitHub (pinned to 12126d8942)