{"record":{"id":"b2798746b91a8977","repo":"apache/beam","slug":"error-encoding-bool-v","errorCode":null,"errorMessage":"error encoding bool: %v","messagePattern":"error encoding bool: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/coder.go","lineNumber":349,"sourceCode":"\tfv := &FullValue{}\n\tif err := d.DecodeTo(r, fv); err != nil {\n\t\treturn nil, err\n\t}\n\treturn fv, nil\n}\n\ntype boolEncoder struct{}\n\nfunc (*boolEncoder) Encode(val *FullValue, w io.Writer) error {\n\t// Encoding: false = 0, true = 1\n\tvar err error\n\tif val.Elm.(bool) {\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 fmt.Errorf(\"error encoding bool: %v\", err)\n\t}\n\treturn nil\n}\n\ntype boolDecoder struct{}\n\nfunc (*boolDecoder) DecodeTo(r io.Reader, fv *FullValue) error {\n\t// Encoding: false = 0, true = 1\n\tb := make([]byte, 1)\n\tif err := ioutilx.ReadNBufUnsafe(r, b); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn err\n\t\t}\n\t\treturn fmt.Errorf(\"error decoding bool: %v\", err)\n\t}\n\tswitch b[0] {\n\tcase 0:\n\t\t*fv = FullValue{Elm: false}","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/coder.go#L331-L367","documentation":"The exec coder's Encode writes booleans as a single byte (1 or 0) via an unsafe fast-path write to the output writer. If that underlying write fails, the error is wrapped as 'error encoding bool'. The failure reflects an I/O problem with the destination stream, not the value itself.","triggerScenarios":"Encoding a FullValue whose Elm is a bool into a writer that is closed, broken (pipe), or at an I/O error; cascading failures when an earlier write in the stream already failed.","commonSituations":"Writing to a network/shuffle connection that dropped mid-record; encoding to a closed bytes.Buffer-adjacent writer or file handle; disk-full conditions during pipeline data transport.","solutions":["Inspect the wrapped inner error to identify the underlying I/O failure.","Ensure the destination writer remains open and healthy for the duration of encoding.","Check for earlier stream failures (a broken pipe usually affects all subsequent writes).","Add retry/reconnect logic at the transport layer if writing over the network."],"exampleFix":"// before: encoding into a writer that may be closed\nerr := enc.Encode(w, val)\n// after: verify writer is live and handle wrapped errors\nif c, ok := w.(io.Closer); ok && c == closedWriter { return errors.New(\"writer closed\") }\nif err := enc.Encode(w, val); err != nil { log.Printf(\"encode failed: %v\", errors.Unwrap(err)) }","handlingStrategy":"try-catch","validationCode":"// Verify writer health before encoding:\nif w == nil { return errors.New(\"nil writer\") }","typeGuard":"func writerHealthy(w io.Writer) bool { type c interface{ Close() error }; if cw, ok := w.(c); ok { _ = cw }; return w != nil }","tryCatchPattern":"if err := enc.Encode(w, val); err != nil {\n    if strings.Contains(err.Error(), \"error encoding bool\") {\n        return fmt.Errorf(\"transport failure: %w\", errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Keep the destination stream open for the whole record","Check transport health on connection drops","Treat the first write error as the root cause for cascading failures"],"tags":["go","apache-beam","encoding","io","bool"],"backgroundTag":"file-write-failed","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"}