{"record":{"id":"0dd72a8d5687a5bb","repo":"apache/beam","slug":"bad-kv-v","errorCode":null,"errorMessage":"bad KV: %v","messagePattern":"bad KV: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/dataflow.go","lineNumber":110,"sourceCode":"func EncodeCoderRef(c *coder.Coder) (*CoderRef, error) {\n\tswitch c.Kind {\n\tcase coder.Custom:\n\t\tref, err := encodeCustomCoder(c.Custom)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdata, err := protox.EncodeBase64(ref)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &CoderRef{\n\t\t\tType:       lengthPrefixType,\n\t\t\tComponents: []*CoderRef{{Type: data, PipelineProtoCoderID: c.Custom.ID}},\n\t\t}, nil\n\n\tcase coder.KV:\n\t\tif len(c.Components) != 2 {\n\t\t\treturn nil, errors.Errorf(\"bad KV: %v\", c)\n\t\t}\n\n\t\tkey, err := EncodeCoderRef(c.Components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tvalue, err := EncodeCoderRef(c.Components[1])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn &CoderRef{Type: pairType, Components: []*CoderRef{key, value}, IsPairLike: true}, nil\n\n\tcase coder.Nullable:\n\t\tif len(c.Components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"bad N: %v\", c)\n\t\t}\n\t\tinnerref, err := EncodeCoderRef(c.Components[0])\n\t\tif err != nil {","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/dataflow.go#L92-L128","documentation":"Produced by EncodeCoderRef in graphx/dataflow.go when converting a coder.KV to its Dataflow-protocol CoderRef: the legacy Dataflow representation requires exactly two components (key and value), so a KV with any other component count is rejected with 'bad KV'.","triggerScenarios":"EncodeCoderRef/EncodeCoder on a *coder.Coder with Kind == coder.KV and len(c.Components) != 2 — e.g. a KV constructed with 0, 1, or 3+ components.","commonSituations":"Hand-built coder.KV with a wrong component list; coders arriving from other SDKs or legacy job submissions whose KV arity differs; corrupted pipeline graphs deserialized incorrectly; submitting to legacy Dataflow where EncodeCoderRef is used.","solutions":["Log c.Components length; rebuild the KV with exactly two components via coder.NewKV([]*coder.Coder{key, value}).","Trace where the malformed KV was created (custom coder construction or cross-language expansion).","Ensure pipeline coders are generated by Beam constructors rather than assembled manually.","If the coder comes from another SDK, check version compatibility and the pipeline's serialized graph.","For non-pair structured types, use an iterable/custom coder instead of KV."],"exampleFix":"// before\nbad := coder.NewKV([]*coder.Coder{keyOnly})\nref, err := graphx.EncodeCoderRef(bad)\n// after\ngood := coder.NewKV([]*coder.Coder{key, value})\nref, err := graphx.EncodeCoderRef(good)","handlingStrategy":"validation","validationCode":"if c.Kind == coder.KV && len(c.Components) != 2 {\n    return fmt.Errorf(\"KV coder must have exactly 2 components, got %d\", len(c.Components))\n}","typeGuard":"func isWellFormedKV(c *coder.Coder) bool {\n    return c != nil && c.Kind == coder.KV && len(c.Components) == 2\n}","tryCatchPattern":"ref, err := graphx.EncodeCoderRef(c)\nif err != nil && strings.HasPrefix(err.Error(), \"bad KV\") {\n    return fmt.Errorf(\"KV arity invalid (%d components): %w\", len(c.Components), err)\n}","preventionTips":["Always create KVs with coder.NewKV(key, value) — exactly two components.","Never mutate c.Components on a KV coder after construction.","Validate coder arity before legacy Dataflow submission paths."],"tags":["go","apache-beam","dataflow","kv-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-20T03:17:13.778Z"}