{"record":{"id":"968279a5dc93a157","repo":"apache/beam","slug":"array-len-mismatch-decoding-v-but-only-have-v-elements","errorCode":null,"errorMessage":"array len mismatch. decoding %v but only have %v elements.","messagePattern":"array len mismatch\\. decoding (.+?) but only have (.+?) elements\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/coder.go","lineNumber":807,"sourceCode":"\n// arrayDecoder reads the same format as iterableDecoder but\n// produces arrays instead of slices, taking the encoded length\n// as the length of the array.\ntype arrayDecoder struct {\n\tt   reflect.Type // array type\n\tdec ElementDecoder\n}\n\nfunc (c *arrayDecoder) DecodeTo(r io.Reader, fv *FullValue) error {\n\t// (1) Read count prefixed encoded data\n\n\tsize, err := coder.DecodeInt32(r)\n\tif err != nil {\n\t\treturn err\n\t}\n\tn := int(size)\n\tif n != c.t.Len() {\n\t\treturn errors.Errorf(\"array len mismatch. decoding %v but only have %v elements.\", c.t, n)\n\t}\n\tswitch {\n\tcase n >= 0:\n\t\trv := reflect.New(c.t).Elem()\n\t\tvar e FullValue\n\t\tfor i := 0; i < int(n); i++ {\n\t\t\terr := c.dec.DecodeTo(r, &e)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif e.Elm != nil {\n\t\t\t\trv.Index(i).Set(reflect.ValueOf(e.Elm))\n\t\t\t}\n\t\t}\n\t\t*fv = FullValue{Elm: rv.Interface()}\n\t\treturn nil\n\tdefault:\n\t\treturn errors.Errorf(\"unable to decode array with iterable marker %v\", n)","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/coder.go#L789-L825","documentation":"When decoding an array-typed element, the exec decoder reads an int32 element count from the wire and compares it to the target reflect type's length (c.t.Len()). If the encoded count differs from the fixed-length array type, decoding aborts with this error. It means the wire data doesn't match the declared Go array type.","triggerScenarios":"arrayDecoder.DecodeTo reads n != c.t.Len() — e.g. decoding data written as a variable-length slice or from a different-size array type ([3]int32 vs [4]int32).","commonSituations":"Pipeline updates where an array's length changed between job versions; cross-language pipelines where the sender uses a dynamic-size type; stale checkpoints/snapshots with old schemas.","solutions":["Ensure the encoding and decoding sides use the identical fixed-size array type.","If length is dynamic, switch the PCollection to a slice ([]T) instead of a fixed array.","Re-generate or refresh stale data/checkpoints produced under a previous schema.","Verify cross-language coder mappings agree on array size."],"exampleFix":"// before\ncol := beam.Create(s, [3]int32{1, 2, 3}) // decoded elsewhere as [4]int32\n// after\nmatch sizes on both sides: [3]int32 encoded and [3]int32 decoded\n// or use a slice:\ncol := beam.Create(s, []int32{1, 2, 3})","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// ensure the decode target matches the encoded fixed-size array\nfunc arrayLenMatches(t reflect.Type, n int) bool {\n    return t.Kind() == reflect.Array && t.Len() == n\n}","tryCatchPattern":"if err := dec.DecodeTo(r, fv); err != nil {\n    if strings.Contains(err.Error(), \"array len mismatch\") {\n        return fmt.Errorf(\"wire data does not match declared array type %s: %w\", c.t, err)\n    }\n    return err\n}","preventionTips":["Never change fixed array sizes in a schema without draining/re-encoding in-flight data.","Prefer slices over fixed-size arrays for variable-length data.","Ensure cross-language counterparts declare the same array length.","Version-check encoded blobs before decoding after a pipeline update."],"tags":["go","apache-beam","decoding","array","coder"],"backgroundTag":"shape-mismatch","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"}