{"record":{"id":"768b08273c29dc9d","repo":"apache/beam","slug":"error-decoding-bool-received-invalid-value-v-768b08","errorCode":null,"errorMessage":"error decoding bool: received invalid value %v","messagePattern":"error decoding bool: received invalid value (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/bool.go","lineNumber":56,"sourceCode":"}\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":38,"sourceCodeEnd":58,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/bool.go#L38-L58","documentation":"The Beam protocol encodes booleans as exactly the bytes 0 or 1. If the decoded byte is anything else, DecodeBool throws this error because the stream violates the protocol. This almost always means data corruption or an offset/alignment bug where a non-boolean byte is being read as a bool.","triggerScenarios":"DecodeBool(r) reads a byte whose value is not 0 or 1 — misaligned stream position, corrupted data, or decoding bytes with the wrong coder.","commonSituations":"Using a bool coder on bytes produced by another coder; coder mismatch after changing a PCollection's element type without re-encoding stored data; corrupt checkpoints or shuffled data files.","solutions":["Check coder alignment: the reader must be positioned exactly at a bool-encoded byte (0/1).","Verify the data was encoded with EncodeBool and not another coder; fix the coder used on the write side.","Inspect the invalid byte value in the message to identify what is actually in the stream.","Regenerate corrupted stored/checkpointed data; ensure full-record writes (no partial records)."],"exampleFix":"// before: decoding a length-prefixed stream with bool coder\nv, _ := DecodeBool(r) // reads wrong byte\n// after: read the length first, then decode\nn, _ := coder.DecodeVarInt(r)\nv, _ := DecodeBool(r)","handlingStrategy":"validation","validationCode":"// Go: guard stream position before decoding a bool\n// verify the next byte is 0 or 1 by peeking when the reader supports it\n// (bufio.Reader Peek)\nbr := bufio.NewReader(r)\nif b, err := br.Peek(1); err == nil && b[0] > 1 {\n    return fmt.Errorf(\"stream misaligned: next byte %d is not a bool\", b[0])\n}","typeGuard":null,"tryCatchPattern":"// Go\nv, err := coder.DecodeBool(r)\nif err != nil && !errors.Is(err, io.EOF) {\n    return fmt.Errorf(\"invalid bool byte at stream pos: %w\", err)\n}","preventionTips":["Match coders exactly between encode and decode sides.","Never reuse a bool coder on data written by other coders.","Regenerate corrupted stored data; keep record framing intact.","Log the invalid byte value to diagnose alignment issues."],"tags":["go","decoding","data-corruption","beam-coder"],"backgroundTag":"unexpected-response-shape","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"}