apache/beam · error
error encoding bool
Error message
error encoding bool
What it means
EncodeBool writes a single byte (0 or 1) per the Beam runner protocol; this wraps any I/O failure from that write with 'error encoding bool'. It indicates the underlying writer failed mid-serialization, not a type problem. Common underlying causes are broken pipes, closed writers, or disk/network errors when the coder output goes to a stream or file.
Source
Thrown at sdks/go/pkg/beam/core/graph/coder/bool.go:35
import (
"io"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/ioutilx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
)
// EncodeBool encodes a boolean according to the beam protocol.
func EncodeBool(v bool, w io.Writer) error {
// Encoding: false = 0, true = 1
var err error
if v {
_, 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:View on GitHub (pinned to 12126d8942)
Solutions
- Inspect the wrapped cause (errors.Unwrap) to find the real I/O failure (broken pipe, closed connection, disk full).
- Check network/worker health if this occurs during pipeline execution; retry the affected stage.
- Verify custom sinks keep the writer open for the duration of encoding.
- Add retry/timeout handling on the transport feeding the io.Writer.
Example fix
// before: writer may be closed before encode finishes w.Close() EncodeBool(true, w) // after: encode first, then close EncodeBool(true, w) w.Close()
Defensive patterns
Strategy: try-catch
Try / catch
// Go
if err := coder.EncodeBool(v, w); err != nil {
cause := errors.Unwrap(err)
log.Printf("bool encode failed: %v", cause) // inspect real I/O error
return err
} Prevention
- Keep writers open until all encoding completes.
- Monitor worker network health during pipeline runs.
- Handle broken pipes and disk-full conditions on custom sinks.
When it happens
Trigger: EncodeBool(v, w) when w is closed, broken (pipe), or returns a write error — e.g. during sink serialization to a failed network stream or full disk.
Common situations: Runner shut down while a stage is still encoding elements; network failures streaming encoded records between workers; writing to a closed file or connection in custom sinks.
Related errors
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9ded0a6230980505.
Report an issue: GitHub.