apache/beam · error
error decoding bool: received invalid value
Error message
error decoding bool: received invalid value %v
What it means
This error comes from the Beam Go SDK's boolDecoder in exec/coder.go. During decoding of a wire-encoded boolean, the decoder found a byte that is neither 0 nor 1, so it cannot reconstruct a bool FullValue. It indicates corrupt or non-conforming encoded data rather than user-facing API misuse.
Solutions
- Verify the coder registry and coder IDs match between pipeline construction and the worker runtime (same Beam SDK version).
- Re-generate or clear any cached/serialized data (state caches, test fixtures) that may be corrupted.
- Check that stream offsets and reader boundaries are aligned to element boundaries; a partial read yields invalid bytes.
- Log the raw byte value (%v) to identify what is actually being read and trace where the stream diverged.
Example fix
// before: decoding raw bytes with mismatched coder
dec := exec.MakeElementDecoder(badCoder)
fv, err := dec.Decode(r)
// after: ensure coder comes from the same model pipeline / registry
dec := exec.MakeElementDecoder(coder.FromProto(modelPipelineComponents))
fv, err := dec.Decode(r)
if err != nil {
return fmt.Errorf("bool decode failed, check coder consistency: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if b != 0 && b != 1 { return fmt.Errorf("invalid bool byte %d before decode", b) } Type guard
func isValidBoolByte(b byte) bool { return b == 0 || b == 1 } Try / catch
fv, err := dec.Decode(r)
if err != nil {
if strings.Contains(err.Error(), "error decoding bool") {
return fmt.Errorf("corrupt stream or coder mismatch: %w", err)
}
return err
} Prevention
- Pin the same Beam SDK version for pipeline submission and workers
- Never hand-edit encoded element bytes or test fixtures
- Keep reader offsets aligned to element boundaries
When it happens
Trigger: Calling Decode/DecodeTo on a stream whose underlying bytes were produced with a different coder, truncated mid-element, or manually crafted so the bool byte is not 0 or 1.
Common situations: Corrupted pipeline artifacts or state caches, mismatched coder versions between job submitter and worker, manually edited captured streams, or reading a stream offset into the middle of an element.
Related errors
- array len mismatch. decoding
- CoderException
- Could not decode provided windows with the provided window…
- decodeStream value decode failed
- Encountered unexpected value for null indicator
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/2a93f85e6de96014.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/exec/coder.go:373
func (*boolDecoder) DecodeTo(r io.Reader, fv *FullValue) error {
// Encoding: false = 0, true = 1
b := make([]byte, 1)
if err := ioutilx.ReadNBufUnsafe(r, b); err != nil {
if err == io.EOF {
return err
}
return fmt.Errorf("error decoding bool: %v", err)
}
switch b[0] {
case 0:
*fv = FullValue{Elm: false}
return nil
case 1:
*fv = FullValue{Elm: true}
return nil
}
return fmt.Errorf("error decoding bool: received invalid value %v", b)
}
func (d *boolDecoder) Decode(r io.Reader) (*FullValue, error) {
fv := &FullValue{}
if err := d.DecodeTo(r, fv); err != nil {
return nil, err
}
return fv, nil
}
type varIntEncoder struct{}
func (*varIntEncoder) Encode(val *FullValue, w io.Writer) error {
// Encoding: beam varint
return coder.EncodeVarInt(val.Elm.(int64), w)
}
type varIntDecoder struct{}View on GitHub (pinned to 12126d8942)