apache/beam · error
encoding %v, expected: %q
Error message
encoding %v, expected: %q
What it means
Wrap added by the reflective row encoder's per-field loop: the encode function for field i failed, and the message records the field's Go type plus the expected schema field description from coder.debug. This pinpoints which struct field of the row could not be serialized, with the underlying cause (e.g. failed inner encode) wrapped inside.
Source
Thrown at sdks/go/pkg/beam/core/graph/coder/row_encoder.go:350
}
return func(rv reflect.Value, w io.Writer) error {
if err := writeRowHeader(rv, w); err != nil {
return err
}
for i, f := range coder.fields {
rvf := rv.Field(i)
switch rvf.Kind() {
case reflect.Ptr, reflect.Map, reflect.Slice:
if rvf.IsNil() {
continue
}
}
if f.addr {
rvf = rvf.Addr()
}
if err := f.encode(rvf, w); err != nil {
return errors.Wrapf(err, "encoding %v, expected: %q", rvf.Type(), coder.debug[i])
}
}
return nil
}, nil
}
View on GitHub (pinned to 12126d8942)
Solutions
- Inspect the wrapped cause for the root writer/encode failure
- Check that the destination writer is open and writable throughout the encode
- Verify nested field values are encodable (no nil or unsupported values in nested containers)
Defensive patterns
Strategy: try-catch
Try / catch
if err := enc.Encode(v, w); err != nil {
log.Printf("row encode failed at field (see wrapped cause): %v", err)
return err
} Prevention
- Keep writers open and healthy for the duration of encoding
- Test encode of representative values including nested containers
- Check wrapped cause chains to identify the failing field type
When it happens
Trigger: During row encoding of any struct/slice element, when a field encoder (e.g. nested bytes/struct writer) returns an error such as short writes or unsupported nested value.
Common situations: Underlying writer failing mid-row (closed writer, disk full), or nested field coder errors surfaced during pipeline execution.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- varint too long
- error encoding byte: %v
- error encoding pane %v: non-speculative index value must be
- number of fields is less than byte array %v < %v
- WriteSimpleRowHeader a 0 length nils bit field: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/c2405160dd69f6d4.
Report an issue: GitHub.