{"record":{"id":"32bfd7cad347e439","repo":"apache/beam","slug":"error-decoding-bool","errorCode":null,"errorMessage":"error decoding bool","messagePattern":"error decoding bool","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/bool.go","lineNumber":48,"sourceCode":"\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:\n\t\treturn true, nil\n\t}\n\treturn false, errors.Errorf(\"error decoding bool: received invalid value %v\", b[0])\n}\n","sourceCodeStart":30,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/bool.go#L30-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"Corrupted or truncated state files / checkpoint data; network drops between workers mid-record; reading from a stream that errored rather than cleanly ended.","solutions":["Distinguish io.EOF (legit end) from the wrapped error via errors.Is/Unwrap; treat wrapped errors as stream corruption.","Verify the data source integrity — re-read or restore from a healthy checkpoint/source.","Check network stability between pipeline workers if decoding streamed records.","Ensure the encoder side wrote a full record (pair EncodeBool failures with this)."],"exampleFix":"// before: treating all errors the same\nok, err := DecodeBool(r)\n// after: handle EOF separately\nok, err := DecodeBool(r)\nif err == io.EOF { /* clean end */ } else if err != nil { /* corruption: refresh source */ }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go\nv, err := coder.DecodeBool(r)\nif err == io.EOF {\n    return false, io.EOF // clean stream end\n}\nif err != nil {\n    return false, fmt.Errorf(\"bool stream corrupt: %w\", err)\n}","preventionTips":["Separate io.EOF from wrapped errors with errors.Is.","Validate integrity of checkpoint/serialized data files.","Ensure the encode side writes complete records.","Add reconnect/retry for networked streams."],"tags":["go","io","decoding","beam-coder"],"backgroundTag":"file-read-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"}