{"record":{"id":"d68b72d23fc5f070","repo":"apache/beam","slug":"error-decoding-byte","errorCode":null,"errorMessage":"error decoding byte","messagePattern":"error decoding byte","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/bytes.go","lineNumber":43,"sourceCode":"\n// EncodeByte encodes a single byte.\nfunc EncodeByte(v byte, w io.Writer) error {\n\t// Encoding: raw byte.\n\tif _, err := ioutilx.WriteUnsafe(w, []byte{v}); err != nil {\n\t\treturn fmt.Errorf(\"error encoding byte: %v\", err)\n\t}\n\treturn nil\n}\n\n// DecodeByte decodes a single byte.\nfunc DecodeByte(r io.Reader) (byte, error) {\n\t// Encoding: raw byte\n\tvar b [1]byte\n\tif err := ioutilx.ReadNBufUnsafe(r, b[:]); err != nil {\n\t\tif err == io.EOF {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn 0, errors.Wrap(err, \"error decoding byte\")\n\t}\n\treturn b[0], nil\n}\n\n// EncodeBytes encodes a []byte with a length prefix per the beam protocol.\nfunc EncodeBytes(v []byte, w io.Writer) error {\n\t// Encoding: size (varint) + raw data\n\tsize := len(v)\n\tif err := EncodeVarInt((int64)(size), w); err != nil {\n\t\treturn err\n\t}\n\t_, err := w.Write(v)\n\treturn err\n\n}\n\n// DecodeBytes decodes a length prefixed []byte according to the beam protocol.\nfunc DecodeBytes(r io.Reader) ([]byte, error) {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/bytes.go#L25-L61","documentation":"DecodeByte reads exactly one raw byte; a read failure other than clean io.EOF is wrapped as 'error decoding byte'. As with DecodeBool, io.EOF passes through unwrapped for legitimate stream end. This points to truncated or failing input rather than an invalid value.","triggerScenarios":"DecodeByte(r) when the underlying reader returns a non-EOF error (reset connection, unreadable/corrupt file, short read with I/O error).","commonSituations":"Reading truncated serialized data files; network errors between pipeline workers; decoding from a closed or erroring reader in custom sources.","solutions":["Use errors.Is(err, io.EOF) to separate clean end-of-stream from real failures.","Validate the data file/stream integrity and re-fetch or restore from a good copy if corrupted.","Check the source reader is open and healthy for the entire decode session.","If streaming over network, add retry/reconnect logic and ensure record framing is intact."],"exampleFix":"// before: ignoring EOF vs real errors\nb, err := DecodeByte(r)\nif err != nil { return err }\n// after\nb, err := DecodeByte(r)\nif err == io.EOF { return io.EOF }\nif err != nil { return fmt.Errorf(\"stream corrupt: %w\", err) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go\nb, err := coder.DecodeByte(r)\nif err == io.EOF {\n    return 0, io.EOF\n}\nif err != nil {\n    return 0, fmt.Errorf(\"byte stream read failed: %w\", err)\n}","preventionTips":["Check reader liveness before long decode loops.","Use errors.Is(err, io.EOF) to distinguish end-of-stream.","Retry/restore corrupted or truncated data sources.","Frame network streams so partial reads are detectable."],"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"}