{"record":{"id":"c08921b6b6890f46","repo":"apache/beam","slug":"expected-cogbk-got-v","errorCode":null,"errorMessage":"expected CoGBK, got %v","messagePattern":"expected CoGBK, got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/cogbk.go","lineNumber":74,"sourceCode":"//                        |\n//                 U4: CoGBK<K,RUV>\n//                        |\n//                      Expand\n//                        |\n//                Out: CoGBK<K,X,Y>\n//\n// Inject and Expand are system-defined functions. This expansion cannot be\n// 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}","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/cogbk.go#L56-L92","documentation":"Produced by MakeKVUnionCoder in graphx/cogbk.go, which builds the reshuffle union coder KV<K,KV<int,[]byte>> for a CoGBK node. If the supplied MultiEdge's Op is not graph.CoGBK, the function refuses to build the coder, since the union layout only makes sense for CoGBK outputs.","triggerScenarios":"Calling MakeKVUnionCoder(gbk) with a *graph.MultiEdge whose Op is, e.g., ParDo, Flatten, or CoGBK-replacement operations — typically from a custom reshuffle/expansion hook passing the wrong edge.","commonSituations":"Custom reshuffle implementations or internal transforms that hand a non-GBK MultiEdge to the union-coder builder; refactored pipeline code where the operation type changed; unit tests exercising the bad-input path.","solutions":["Ensure the MultiEdge passed in was produced by a CoGBK (gbk.Op == graph.CoGBK) before calling.","Check that you are passing gbk *graph.MultiEdge from the correct expansion step (expandCoGBK), not another transform's edge.","Log the MultiEdge (the %v in the message shows the wrong op) and trace where it came from.","If you need a union coder for another op, use or write the appropriate builder rather than reusing MakeKVUnionCoder."],"exampleFix":"// before\nc, err := graphx.MakeKVUnionCoder(parDoEdge)\n// after\nif parDoEdge.Op == graph.CoGBK {\n    c, err = graphx.MakeKVUnionCoder(parDoEdge)\n}","handlingStrategy":"validation","validationCode":"if gbk == nil || gbk.Op != graph.CoGBK {\n    return errors.New(\"MakeKVUnionCoder requires a MultiEdge with Op == graph.CoGBK\")\n}","typeGuard":"func isCoGBKEdge(e *graph.MultiEdge) bool {\n    return e != nil && e.Op == graph.CoGBK\n}","tryCatchPattern":"c, err := graphx.MakeKVUnionCoder(edge)\nif err != nil {\n    return fmt.Errorf(\"kv union coder for %v: %w\", edge.Op, err)\n}","preventionTips":["Only pass CoGBK MultiEdges from expandCoGBK into union-coder builders.","Assert op type at the call site during custom reshuffle work.","Add unit tests that exercise your expansion path with real CoGBK edges."],"tags":["go","apache-beam","cogbk","reshuffle"],"backgroundTag":"invalid-argument-value","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"}