{"record":{"id":"3ccd179f8d6a11c4","repo":"apache/beam","slug":"could-not-unmarshal-kv-coder-from-v-want-exactly-2","errorCode":null,"errorMessage":"could not unmarshal KV coder from %v, want exactly 2 components but have %d","messagePattern":"could not unmarshal KV coder from (.+?), want exactly 2 components but have (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/coder.go","lineNumber":212,"sourceCode":"\tswitch urn {\n\tcase urnBytesCoder:\n\t\treturn coder.NewBytes(), nil\n\n\tcase urnBoolCoder:\n\t\treturn coder.NewBool(), nil\n\n\tcase urnVarIntCoder:\n\t\treturn coder.NewVarInt(), nil\n\n\tcase urnDoubleCoder:\n\t\treturn coder.NewDouble(), nil\n\n\tcase urnStringCoder:\n\t\treturn coder.NewString(), nil\n\n\tcase urnKVCoder:\n\t\tif len(components) != 2 {\n\t\t\treturn nil, errors.Errorf(\"could not unmarshal KV coder from %v, want exactly 2 components but have %d\", c, len(components))\n\t\t}\n\n\t\tkey, err := b.Coder(components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tid := components[1]\n\t\telm, err := b.peek(id)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"could not unmarshal kv coder value component: %w\", err)\n\t\t}\n\n\t\tswitch elm.GetSpec().GetUrn() {\n\t\tcase urnIterableCoder, urnStateBackedIterableCoder:\n\t\t\titerElmID := elm.GetComponentCoderIds()[0]\n\n\t\t\t// TODO(https://github.com/apache/beam/issues/18032): If CoGBK with > 1 input, handle as special GBK. We expect","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/coder.go#L194-L230","documentation":"When makeCoder encounters a KV coder URN, it expects exactly two component coders (key and value). If the coder proto lists a different number of components, unmarshaling fails with this error including the raw coder proto and the actual component count.","triggerScenarios":"makeCoder processing beam:coders:kv:v1 with components != 2, typically from a malformed or hand-edited pipeline proto, or a runner emitting a KV coder with wrong component arity.","commonSituations":"Custom runners or foreign SDKs producing non-conformant KV coders; corrupted pipeline serialization; manual proto construction that forgot one KV component.","solutions":["Inspect the printed coder proto in the error and ensure the KV coder declares exactly 2 component coder IDs.","Fix the pipeline construction code so KV PCollections register both key and value coders.","Regenerate the pipeline with a standard Beam SDK rather than hand-building coder protos.","Check the producing runner/SDK for known bugs in coder serialization."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if c := comps.GetCoders()[kvCoderID]; c != nil && len(c.GetComponentCoderIds()) != 2 {\n    return fmt.Errorf(\"KV coder %s must have 2 components, has %d\", kvCoderID, len(c.GetComponentCoderIds()))\n}","typeGuard":null,"tryCatchPattern":"cd, err := um.Coder(id)\nif err != nil && strings.Contains(err.Error(), \"want exactly 2 components\") {\n    log.Printf(\"malformed KV coder proto: %v\", err)\n}","preventionTips":["Use the standard Beam SDK pipeline building code to emit KV coders.","Validate coder component arity before submitting custom-built protos.","Round-trip marshal/unmarshal in tests to catch malformed coders."],"tags":["go","coder","kv","arity"],"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-20T03:17:13.778Z"}