{"record":{"id":"9ded0a6230980505","repo":"apache/beam","slug":"error-encoding-bool","errorCode":null,"errorMessage":"error encoding bool","messagePattern":"error encoding bool","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/bool.go","lineNumber":35,"sourceCode":"\nimport (\n\t\"io\"\n\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/ioutilx\"\n\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors\"\n)\n\n// EncodeBool encodes a boolean according to the beam protocol.\nfunc EncodeBool(v bool, w io.Writer) error {\n\t// Encoding: false = 0, true = 1\n\tvar err error\n\tif v {\n\t\t_, err = ioutilx.WriteUnsafe(w, []byte{1})\n\t} else {\n\t\t_, err = ioutilx.WriteUnsafe(w, []byte{0})\n\t}\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"error encoding bool\")\n\t}\n\treturn nil\n}\n\n// DecodeBool decodes a boolean according to the beam protocol.\nfunc DecodeBool(r io.Reader) (bool, error) {\n\t// Encoding: false = 0, true = 1\n\tvar b [1]byte\n\tif err := ioutilx.ReadNBufUnsafe(r, b[:]); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn false, err\n\t\t}\n\t\treturn false, errors.Wrap(err, \"error decoding bool\")\n\t}\n\tswitch b[0] {\n\tcase 0:\n\t\treturn false, nil\n\tcase 1:","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/bool.go#L17-L53","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: writer may be closed before encode finishes\nw.Close()\nEncodeBool(true, w)\n// after: encode first, then close\nEncodeBool(true, w)\nw.Close()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go\nif err := coder.EncodeBool(v, w); err != nil {\n    cause := errors.Unwrap(err)\n    log.Printf(\"bool encode failed: %v\", cause) // inspect real I/O error\n    return err\n}","preventionTips":["Keep writers open until all encoding completes.","Monitor worker network health during pipeline runs.","Handle broken pipes and disk-full conditions on custom sinks."],"tags":["go","io","encoding","beam-coder"],"backgroundTag":"broken-pipe","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}