apache/beam · error
bad base type
Error message
bad base type
What it means
In the Beam Go SDK's graphx type serialization, encodeType recursively encodes reflect.Type values into protobuf form. When encoding a pointer's base (element) type fails, the inner error is wrapped with 'bad base type' and contextualized with 'encoding pointer %v'. It indicates the pointed-to type itself is not serializable by graphx.
Solutions
- Change the pointed-to type to an encodable kind (struct, slice, primitive)
- Wrap the map/array in a struct field, per https://github.com/apache/beam/issues/23101
- Inspect the full wrapped error chain (base error + 'encoding pointer %v' context) to find the offending type
- Register a custom coder for the type via beam.CustomCoder if the type must be kept
Example fix
// before
var x *[10]int
pc := beam.ParDo(s, extractFn, beam.Create(s, x))
// after
type IntArray struct { V [10]int }
pc := beam.ParDo(s, extractFn, beam.Create(s, IntArray{})) Defensive patterns
Strategy: validation
Validate before calling
func isEncodableType(t reflect.Type) bool {
switch t.Kind() {
case reflect.Ptr:
return isEncodableType(t.Elem())
case reflect.Map, reflect.Array:
return false
case reflect.Slice, reflect.Struct:
if t.Kind() == reflect.Struct {
for i := 0; i < t.NumField(); i++ {
if !isEncodableType(t.Field(i).Type) { return false }
}
}
return true
default:
return graphx.TryEncodeSpecial(t) != 0 || isKnownKind(t.Kind())
}
} Type guard
func isEncodable(t reflect.Type) bool { return isEncodableType(t) } Prevention
- Avoid pointer-typed PCollection elements; pass values
- Never use raw map or array types as pipeline element types
- Wrap complex containers in structs, per beam issue 23101
- Test pipeline marshalling locally (graphx.Marshal) before submitting
When it happens
Trigger: Pipelines whose graph contains a pointer type (e.g. *T as an input/output or nested inside another type) where T itself fails encodeType — for example *map[string]int or *[10]int, since Map and Array are unencodable at top level.
Common situations: Users declare DoFn parameters or PCollection elements as pointers to inherently unencodable types (maps, arrays) instead of wrapping them in a struct; surfaces during pipeline submission/marshalling of the model graph.
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/5448c8548fa1fb1c.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/graphx/serialize.go:502
return &v1pb.Type{Kind: v1pb.Type_FUNC, ParameterTypes: in, ReturnTypes: out, IsVariadic: t.IsVariadic()}, nil
case reflect.Chan:
elm, err := encodeType(t.Elem())
if err != nil {
wrapped := errors.Wrap(err, "bad element type")
return nil, errors.WithContextf(wrapped, "encoding channel %v", t)
}
dir, err := encodeChanDir(t.ChanDir())
if err != nil {
wrapped := errors.Wrap(err, "bad channel direction")
return nil, errors.WithContextf(wrapped, "encoding channel %v", t)
}
return &v1pb.Type{Kind: v1pb.Type_CHAN, Element: elm, ChanDir: dir}, nil
case reflect.Ptr:
elm, err := encodeType(t.Elem())
if err != nil {
wrapped := errors.Wrap(err, "bad base type")
return nil, errors.WithContextf(wrapped, "encoding pointer %v", t)
}
return &v1pb.Type{Kind: v1pb.Type_PTR, Element: elm}, nil
case reflect.Map, reflect.Array:
return nil, errors.Errorf("unencodable type '%v', try to wrap the type as a field in a struct, see https://github.com/apache/beam/issues/23101 for details", t.Kind())
default:
return nil, errors.Errorf("unencodable type '%v'", t.Kind())
}
}
func tryEncodeSpecial(t reflect.Type) (v1pb.Type_Special, bool) {
switch t {
case reflectx.Error:
return v1pb.Type_ERROR, true
case reflectx.Context:
return v1pb.Type_CONTEXT, trueView on GitHub (pinned to 12126d8942)