apache/beam · error

error decoding bool

Error message

error decoding bool

What it means

DecodeBool reads one byte via ioutilx.ReadNBufUnsafe; if the read fails with anything other than clean io.EOF, the error is wrapped as 'error decoding bool'. io.EOF is returned unwrapped so callers can detect stream end. This signals a truncated or I/O-failing input stream during decoding.

Source

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

		_, err = ioutilx.WriteUnsafe(w, []byte{1})
	} else {
		_, err = ioutilx.WriteUnsafe(w, []byte{0})
	}
	if err != nil {
		return errors.Wrap(err, "error encoding bool")
	}
	return nil
}

// 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. Distinguish io.EOF (legit end) from the wrapped error via errors.Is/Unwrap; treat wrapped errors as stream corruption.
  2. Verify the data source integrity — re-read or restore from a healthy checkpoint/source.
  3. Check network stability between pipeline workers if decoding streamed records.
  4. Ensure the encoder side wrote a full record (pair EncodeBool failures with this).

Example fix

// before: treating all errors the same
ok, err := DecodeBool(r)
// after: handle EOF separately
ok, err := DecodeBool(r)
if err == io.EOF { /* clean end */ } else if err != nil { /* corruption: refresh source */ }
Defensive patterns

Strategy: try-catch

Try / catch

// Go
v, err := coder.DecodeBool(r)
if err == io.EOF {
    return false, io.EOF // clean stream end
}
if err != nil {
    return false, fmt.Errorf("bool stream corrupt: %w", err)
}

Prevention

When it happens

Trigger: DecodeBool(r) when r returns a non-EOF read error (connection reset, file corruption, partial read) — i.e. fewer than 1 readable byte due to a failed read.

Common situations: Corrupted or truncated state files / checkpoint data; network drops between workers mid-record; reading from a stream that errored rather than cleanly ended.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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