apache/beam · error

error decoding bool: received invalid value %v

Error message

error decoding bool: received invalid value %v

What it means

The Beam protocol encodes booleans as exactly the bytes 0 or 1. If the decoded byte is anything else, DecodeBool throws this error because the stream violates the protocol. This almost always means data corruption or an offset/alignment bug where a non-boolean byte is being read as a bool.

Source

Thrown at sdks/go/pkg/beam/core/graph/coder/bool.go:56

}

// DecodeBool decodes a boolean according to the beam protocol.
func DecodeBool(r io.Reader) (bool, error) {
	// Encoding: false = 0, true = 1
	var b [1]byte
	if err := ioutilx.ReadNBufUnsafe(r, b[:]); err != nil {
		if err == io.EOF {
			return false, err
		}
		return false, errors.Wrap(err, "error decoding bool")
	}
	switch b[0] {
	case 0:
		return false, nil
	case 1:
		return true, nil
	}
	return false, errors.Errorf("error decoding bool: received invalid value %v", b[0])
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Check coder alignment: the reader must be positioned exactly at a bool-encoded byte (0/1).
  2. Verify the data was encoded with EncodeBool and not another coder; fix the coder used on the write side.
  3. Inspect the invalid byte value in the message to identify what is actually in the stream.
  4. Regenerate corrupted stored/checkpointed data; ensure full-record writes (no partial records).

Example fix

// before: decoding a length-prefixed stream with bool coder
v, _ := DecodeBool(r) // reads wrong byte
// after: read the length first, then decode
n, _ := coder.DecodeVarInt(r)
v, _ := DecodeBool(r)
Defensive patterns

Strategy: validation

Validate before calling

// Go: guard stream position before decoding a bool
// verify the next byte is 0 or 1 by peeking when the reader supports it
// (bufio.Reader Peek)
br := bufio.NewReader(r)
if b, err := br.Peek(1); err == nil && b[0] > 1 {
    return fmt.Errorf("stream misaligned: next byte %d is not a bool", b[0])
}

Try / catch

// Go
v, err := coder.DecodeBool(r)
if err != nil && !errors.Is(err, io.EOF) {
    return fmt.Errorf("invalid bool byte at stream pos: %w", err)
}

Prevention

When it happens

Trigger: DecodeBool(r) reads a byte whose value is not 0 or 1 — misaligned stream position, corrupted data, or decoding bytes with the wrong coder.

Common situations: Using a bool coder on bytes produced by another coder; coder mismatch after changing a PCollection's element type without re-encoding stored data; corrupt checkpoints or shuffled data files.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/768b08273c29dc9d. Report an issue: GitHub.