{"record":{"id":"d8d9fff9b9c778c7","repo":"apache/beam","slug":"failed-to-marshal-kv-coder-v","errorCode":null,"errorMessage":"failed to marshal KV coder %v","messagePattern":"failed to marshal KV coder (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/coder.go","lineNumber":479,"sourceCode":"\t\t\t\t\"Make sure the type was registered before calling beam.Init. For example: \"+\n\t\t\t\t\"beam.RegisterType(reflect.TypeOf((*TypeName)(nil)).Elem()). Some types, like maps, slices, arrays, channels, and functions cannot be registered as types.\", c, c.Custom.Type)\n\t\t}\n\t\tdata, err := protox.EncodeBase64(ref)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal custom coder %v\", c)\n\t\t}\n\t\tinner := b.internCoder(&pipepb.Coder{\n\t\t\tSpec: &pipepb.FunctionSpec{\n\t\t\t\tUrn:     urnCustomCoder,\n\t\t\t\tPayload: []byte(data),\n\t\t\t},\n\t\t})\n\t\treturn b.internBuiltInCoder(urnLengthPrefixCoder, inner), nil\n\n\tcase coder.KV:\n\t\tcomp, err := b.AddMulti(c.Components)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal KV coder %v\", c)\n\t\t}\n\t\treturn b.internBuiltInCoder(urnKVCoder, comp...), nil\n\n\tcase coder.Nullable:\n\t\tcomp, err := b.AddMulti(c.Components)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal Nullable coder %v\", c)\n\t\t}\n\t\treturn b.internBuiltInCoder(urnNullableCoder, comp...), nil\n\n\tcase coder.CoGBK:\n\t\tcomp, err := b.AddMulti(c.Components)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal CoGBK coder %v\", c)\n\t\t}\n\t\tvalue := comp[1]\n\t\tif len(comp) > 2 {\n\t\t\t// TODO(https://github.com/apache/beam/issues/18032): don't inject union coder for CoGBK.","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/coder.go#L461-L497","documentation":"Wraps any failure from AddMulti when marshalling the components of a coder.KV coder. If any KV component (key or value) fails to marshal, the whole KV coder marshalling fails with this message plus the underlying cause.","triggerScenarios":"CoderBuilder.Add on a coder.KV whose key or value component coder cannot be marshalled (e.g. unregistered custom types, unencodable component).","commonSituations":"PCollections of KV<customKey, T> where the custom key type wasn't registered; deeply nested coders where the root cause is in an inner component.","solutions":["Read the wrapped (inner) error to find which component failed","Register all custom types used in the KV with beam.RegisterType before beam.Init","Simplify or replace unencodable component types","Check the coder's components are all supported kinds"],"exampleFix":"// before\n// KV<map[string]int, string> — map key type can't be registered\n// after\n// KV<MyKeyStruct, string> with beam.RegisterType(reflect.TypeOf((*MyKeyStruct)(nil)).Elem())","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Unwrap to find the failing component\nwrapped := errors.Unwrap(err)\nlog.Printf(\"KV component failure: %v\", wrapped)","preventionTips":["Register all KV key/value custom types before beam.Init","Prefer primitive or registered struct types for keys","Test pipeline construction for each PCollection type"],"tags":["beam","go","coder","kv"],"backgroundTag":"json-marshal-failed","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"}