apache/beam · error
bad parameter type
Error message
bad parameter type
What it means
encodeType serializes func types by encoding each parameter type in turn; 'bad parameter type' means one of the function's input types failed to encode. This occurs while serializing DoFn/processFn signatures during pipeline graph export.
Solutions
- Change the offending parameter type to an encodable one (slice or exported-field struct).
- Register the parameter's custom type so it serializes as an EXTERNAL type.
- Convert map/array parameters into struct-wrapped or slice forms before passing to the DoFn.
- Follow the wrapped error context ('encoding function %v') to identify which parameter fails.
Example fix
// before
func process(ctx context.Context, m map[string]string) error { ... }
// after
type Attr struct { K, V string }
func process(ctx context.Context, attrs []Attr) error { ... } Defensive patterns
Strategy: validation
Validate before calling
ft := reflect.TypeOf(fn)
for i := 0; i < ft.NumIn(); i++ {
if err := isEncodableType(ft.In(i)); err != nil {
return fmt.Errorf("param %d of %v unencodable: %w", i, ft, err)
}
} Type guard
func encodableParams(fn any) bool { t := reflect.TypeOf(fn); if t.Kind() != reflect.Func { return false }; for i := 0; i < t.NumIn(); i++ { if isEncodableType(t.In(i)) != nil { return false } }; return true } Try / catch
if !encodableParams(fn) {
return fmt.Errorf("function %T has unserializable parameter types", fn)
} Prevention
- Avoid map/array parameters in DoFn signatures
- Ensure struct parameters have only exported fields
- Check that special parameters (context, emit funcs) come from beam's supported set
When it happens
Trigger: A user function (beam.Par / DoFn ProcessElement method) has an input parameter whose type cannot be encoded by encodeType (map/array parameter, struct parameter with unexported fields, unregistered type).
Common situations: DoFns accepting map parameters; functions taking custom struct types with unexported fields; signatures using types unknown to the Beam type registry when running on remote runners.
Related errors
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/f63743d4b57efe11.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/graphx/serialize.go:470
field := &v1pb.Type_StructField{
Name: f.Name,
PkgPath: f.PkgPath,
Type: fType,
Tag: string(f.Tag),
Offset: int64(f.Offset),
Index: encodeInts(f.Index),
Anonymous: f.Anonymous,
}
fields = append(fields, field)
}
return &v1pb.Type{Kind: v1pb.Type_STRUCT, Fields: fields}, nil
case reflect.Func:
var in []*v1pb.Type
for i := 0; i < t.NumIn(); i++ {
param, err := encodeType(t.In(i))
if err != nil {
wrapped := errors.Wrap(err, "bad parameter type")
return nil, errors.WithContextf(wrapped, "encoding function %v", t)
}
in = append(in, param)
}
var out []*v1pb.Type
for i := 0; i < t.NumOut(); i++ {
ret, err := encodeType(t.Out(i))
if err != nil {
wrapped := errors.Wrap(err, "bad return type")
return nil, errors.WithContextf(wrapped, "encoding function %v", t)
}
out = append(out, ret)
}
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 {View on GitHub (pinned to 12126d8942)