apache/beam · error
received unknown value type: want []byte, got %T
Error message
received unknown value type: want []byte, got %T
What it means
The bytes encoder in the exec package expects a FullValue whose Elm is a []byte. If the element holds any other type, this error is returned instead of silently mis-encoding. It means the element's runtime type doesn't match the coder the pipeline assigned to it.
Source
Thrown at sdks/go/pkg/beam/core/runtime/exec/coder.go:313
case coder.ShardedKey:
return &shardedKeyDecoder{
key: MakeElementDecoder(c.Components[0]),
}
default:
panic(fmt.Sprintf("Unexpected coder: %v", c))
}
}
type bytesEncoder struct{}
func (*bytesEncoder) Encode(val *FullValue, w io.Writer) error {
// Encoding: size (varint) + raw data
var data []byte
data, ok := val.Elm.([]byte)
if !ok {
return errors.Errorf("received unknown value type: want []byte, got %T", val.Elm)
}
return coder.EncodeBytes(data, w)
}
type bytesDecoder struct{}
func (*bytesDecoder) DecodeTo(r io.Reader, fv *FullValue) error {
// Encoding: size (varint) + raw data
data, err := coder.DecodeBytes(r)
if err != nil {
return err
}
*fv = FullValue{Elm: data}
return nil
}
func (d *bytesDecoder) Decode(r io.Reader) (*FullValue, error) {
fv := &FullValue{}View on GitHub (pinned to 12126d8942)
Solutions
- Make the DoFn emit []byte: convert with []byte(str) before output.
- Fix the PCollection type declaration so the coder matches the element type.
- Check beam.Encoded / coder registration so strings use a string coder, not the bytes coder.
- Add a type assertion in the DoFn to fail early with a clearer message.
Example fix
// before out.Emit(ctx, s) // s is a string into a bytes-coder PCollection // after out.Emit(ctx, []byte(s))
Defensive patterns
Strategy: type-guard
Validate before calling
// guard elements before emitting into a bytes-coder PCollection
func assertBytes(v any) ([]byte, error) {
b, ok := v.([]byte)
if !ok {
return nil, fmt.Errorf("bytes coder requires []byte, got %T", v)
}
return b, nil
} Type guard
func isByteSlice(v any) bool {
_, ok := v.([]byte)
return ok
} Try / catch
if err := enc.Encode(fv, w); err != nil {
if strings.Contains(err.Error(), "want []byte") {
return fmt.Errorf("element type %T does not match bytes coder: %w", fv.Elm, err)
}
return err
} Prevention
- Convert strings/other types to []byte before emitting into bytes-coded PCollections.
- Keep the PCollection's declared element type in sync with what DoFns actually emit.
- Use beam.Encoded or explicit coder registration deliberately, not accidentally.
- Add a quick unit test asserting the emitted type matches the coder.
When it happens
Trigger: bytesEncoder.Encode is called with a FullValue whose Elm is, e.g., a string or custom struct instead of []byte — usually a coder/type mismatch between the PCollection's declared type and emitted values.
Common situations: Emitting string values into a PCollection declared as []byte; schema inference picking the bytes coder for a differently-typed element; unsafe type assertions bypassed by reflection.
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
- not a float type: %v
- not a signed integer type: %v
- not a unsigned integer type: %v
- coder type %v must be identical to node type %v
- GroupByKey requires its input to use KvCoder
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5feb492864cb9301.
Report an issue: GitHub.