{"record":{"id":"d4331a78e99ce732","repo":"apache/beam","slug":"readsimplerowheader-field-count-mismatch-got-v-want-v","errorCode":null,"errorMessage":"ReadSimpleRowHeader field count mismatch, got %v, want %v","messagePattern":"ReadSimpleRowHeader field count mismatch, got (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/coder/row.go","lineNumber":218,"sourceCode":"\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 {\n\t\treturn fmt.Errorf(\"ReadSimpleRowHeader reading nils count: %v, %v\", n, err)\n\t}\n\tif n != 0 {\n\t\treturn fmt.Errorf(\"ReadSimpleRowHeader expected no nils encoded count, got %v\", n)\n\t}\n\treturn nil\n}\n","sourceCodeStart":200,"sourceCodeEnd":229,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/coder/row.go#L200-L229","documentation":"After successfully reading the field count in ReadSimpleRowHeader, it validates that the count matches the number of fields the caller expects for the row type. This error means the header declares a different field count than the schema being decoded into — the data and the target type disagree, so decoding aborts.","triggerScenarios":"Calling ReadSimpleRowHeader(fields, r) where fields does not match the varint in the stream: decoding data written from a different struct/schema, after a schema change (fields added/removed), or pointing the reader at the wrong record.","commonSituations":"Evolving a Go struct used with the row coder without re-serializing old data; serializing in one pipeline version and decoding in another with a changed schema; unit tests with mismatched expectations.","solutions":["Align the schema: decode with the field count the data was actually written with.","Re-serialize stored data after changing the row struct's fields.","Check Beam SDK versions between writer and reader for coder format changes.","In tests, pass the same field count used by the encoder helper (e.g. WriteSimpleRowHeader)."],"exampleFix":"// before\n// struct gained a field after data was written\ncoder.ReadSimpleRowHeader(4, r) // data has 3 fields\n// after\ncoder.ReadSimpleRowHeader(3, r) // match the count the data was written with","handlingStrategy":"validation","validationCode":"// verify expected field count against the schema used when data was written\nif expectedFields != writtenFields { return fmt.Errorf(\"schema drift: data has %d fields, decoder expects %d\", writtenFields, expectedFields) }","typeGuard":null,"tryCatchPattern":"err := coder.ReadSimpleRowHeader(fields, r)\nif err != nil && strings.Contains(err.Error(), \"field count mismatch\") {\n\treturn fmt.Errorf(\"row schema changed since data was written: %w\", err)\n}","preventionTips":["Re-serialize stored row data whenever the row struct's fields change.","Version serialized datasets alongside schema changes.","In tests, always pair WriteSimpleRowHeader(n, ...) with ReadSimpleRowHeader(n, ...) using the same n."],"tags":["go","beam","serialization","row-coder","schema-mismatch"],"backgroundTag":"schema-validation-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"}