{"record":{"id":"ed5198409f17c02a","repo":"apache/beam","slug":"writesimplerowheader-a-0-length-nils-bit-field-v","errorCode":null,"errorMessage":"WriteSimpleRowHeader a 0 length nils bit field: %v","messagePattern":"WriteSimpleRowHeader a 0 length nils bit field: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/row.go","lineNumber":203,"sourceCode":"// and returns true if the field at that index wasn't encoded\n// and can be skipped in decoding.\nfunc IsFieldNil(nils []byte, f int) bool {\n\ti, b := f/8, f%8\n\t// https://github.com/apache/beam/issues/21232: The row header can elide trailing 0 bytes,\n\t// and we shouldn't care if there are trailing 0 bytes when doing a lookup.\n\treturn i < len(nils) && len(nils) != 0 && (nils[i]>>uint8(b))&0x1 == 1\n}\n\n// WriteSimpleRowHeader is a convenience function to write Beam Schema Row Headers\n// for values that do not have any nil fields. Writes the number of fields total\n// and a 0 len byte slice to indicate no fields are nil.\nfunc WriteSimpleRowHeader(fields int, w io.Writer) error {\n\tif err := EncodeVarInt(int64(fields), w); err != nil {\n\t\treturn err\n\t}\n\t// Never nils, so we write the 0 byte header.\n\tif err := EncodeVarInt(0, w); err != nil {\n\t\treturn fmt.Errorf(\"WriteSimpleRowHeader a 0 length nils bit field: %v\", err)\n\t}\n\treturn nil\n}\n\n// ReadSimpleRowHeader is a convenience function to read Beam Schema Row Headers\n// for values that do not have any nil fields. Reads and validates the number of\n// fields total (returning an error for mismatches, and checks that there are\n// no nils encoded as a bit field.\nfunc ReadSimpleRowHeader(fields int, r io.Reader) error {\n\tn, err := DecodeVarInt(r)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"ReadSimpleRowHeader field count: %v, %v\", n, err)\n\t}\n\tif int(n) != fields {\n\t\treturn fmt.Errorf(\"ReadSimpleRowHeader field count mismatch, got %v, want %v\", n, fields)\n\t}\n\tn, err = DecodeVarInt(r)\n\tif err != nil {","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/row.go#L185-L221","documentation":"WriteSimpleRowHeader first encodes the field count as a varint, then writes a varint 0 as the nils bit-field length (simple rows have no nil fields). If the second EncodeVarInt fails, it is wrapped with this message. The odd wording ('a 0 length nils bit field') reflects the wrapped varint-encoding error.","triggerScenarios":"Calling WriteSimpleRowHeader when the underlying io.Writer fails during the second EncodeVarInt — closed stream, broken pipe on the harness data channel, or a failing buffer.","commonSituations":"Pipeline execution where the writer side of a bundle stream dies mid-header; tests using failing writers; writing to a closed file/pipe.","solutions":["Fix the underlying writer error surfaced in the wrapped %v (reopen stream, restore connection).","Ensure the io.Writer stays open for the whole encode operation.","If in a runner, let the framework retry the failed bundle.","Check disk/pipe health when writing serialized rows to files or FIFOs."],"exampleFix":"// before\nf, _ := os.OpenFile(path, os.O_WRONLY, 0) // no write permission / wrong flags\ncoder.WriteSimpleRowHeader(3, f)\n// after\nf, err := os.Create(path)\nif err != nil { return err }\ndefer f.Close()\ncoder.WriteSimpleRowHeader(3, f)","handlingStrategy":"try-catch","validationCode":"if w == nil { return errors.New(\"nil writer passed to WriteSimpleRowHeader\") }","typeGuard":null,"tryCatchPattern":"if err := coder.WriteSimpleRowHeader(n, w); err != nil {\n\tif errors.Is(err, syscall.EPIPE) { /* reopen stream before retry */ }\n\treturn err\n}","preventionTips":["Open output files with write-capable flags and check errors.","Keep streams open across the whole header+rows write sequence.","Handle broken pipes on FIFO/network sinks before encoding rows."],"tags":["go","beam","serialization","row-coder","io"],"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"}