{"record":{"id":"55ae84a4192e9f75","repo":"apache/beam","slug":"failed-to-make-kv-union-coder","errorCode":null,"errorMessage":"failed to make KV Union coder.","messagePattern":"failed to make KV Union coder\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/cogbk.go","lineNumber":82,"sourceCode":"// expressed as Go user code.\n\nconst (\n\tURNInject = \"beam:go:transform:inject:v1\"\n\tURNExpand = \"beam:go:transform:expand:v1\"\n)\n\n// MakeKVUnionCoder returns KV<K,KV<int,[]byte>> for a given CoGBK.\nfunc MakeKVUnionCoder(gbk *graph.MultiEdge) (*coder.Coder, error) {\n\tif gbk.Op != graph.CoGBK {\n\t\terr := errors.Errorf(\"expected CoGBK, got %v\", gbk)\n\t\treturn nil, errors.WithContext(err, \"failed to make KV Union coder\")\n\t}\n\n\tfrom := gbk.Input[0].From\n\tkey := from.Coder.Components[0]\n\tkvCoder, err := makeUnionCoder()\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to make KV Union coder.\")\n\t}\n\treturn coder.NewKV([]*coder.Coder{key, kvCoder}), nil\n}\n\n// MakeGBKUnionCoder returns CoGBK<K,KV<int,[]byte>> for a given CoGBK.\nfunc MakeGBKUnionCoder(gbk *graph.MultiEdge) (*coder.Coder, error) {\n\tif gbk.Op != graph.CoGBK {\n\t\terr := errors.Errorf(\"expected CoGBK, got %v\", gbk)\n\t\treturn nil, errors.WithContext(err, \"failed to make GBK Union coder\")\n\t}\n\n\tfrom := gbk.Input[0].From\n\tkey := from.Coder.Components[0]\n\tkvCoder, err := makeUnionCoder()\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"failed to make GBK Union coder.\")\n\t}\n\treturn coder.NewCoGBK([]*coder.Coder{key, kvCoder}), nil","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/cogbk.go#L64-L100","documentation":"Produced by MakeKVUnionCoder when its internal makeUnionCoder() call fails while constructing KV<int,[]byte>. The SDK wraps that failure with 'failed to make KV Union coder.' so callers know the CoGBK reshuffle coder could not be assembled.","triggerScenarios":"Calling MakeKVUnionCoder on a valid CoGBK MultiEdge, but makeUnionCoder() returns an error (e.g. failure constructing the varintz/bytes component coders).","commonSituations":"Rare internal failure while setting up reshuffle coders for CoGBK; corrupted or edge-case coder registries in custom builds; surfaced mainly in tests like TestMakeKVUnionCoder_bad and pipeline expansion code.","solutions":["Inspect the wrapped cause from makeUnionCoder for the root failure.","Retry after upgrading to a stable Beam release, since this is an internal construction path.","Verify no local modifications to graphx coder construction (varintz coder) are broken.","If reproducible, file an Apache Beam issue with the wrapped error and pipeline shape.","As a workaround, avoid forcing reshuffle (or use a Beam version where expandCoGBK union coding is healthy)."],"exampleFix":"// before\nc, err := graphx.MakeKVUnionCoder(gbkEdge) // err: failed to make KV Union coder.\n// after\nif err != nil {\n    log.Printf(\"union coder build failed: %v\", err) // inspect wrapped cause\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if gbk == nil || len(gbk.Input) == 0 || gbk.Input[0].From == nil || gbk.Input[0].From.Coder == nil {\n    return errors.New(\"CoGBK edge lacks input coder needed for union coder\")\n}","typeGuard":"func hasInputCoder(e *graph.MultiEdge) bool {\n    return e != nil && len(e.Input) > 0 && e.Input[0].From != nil && e.Input[0].From.Coder != nil\n}","tryCatchPattern":"kvCoder, err := makeUnionCoder()\nif err != nil {\n    return nil, fmt.Errorf(\"KV union coder: %w\", err)\n}","preventionTips":["Run on unmodified stable Beam releases for this internal path.","Keep input node coders populated before expansion.","Report reproducible failures upstream with full wrapped error chains."],"tags":["go","apache-beam","cogbk","coder-construction"],"backgroundTag":"internal-invariant-violation","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"}