{"record":{"id":"992477e2e0f20e38","repo":"apache/beam","slug":"could-not-unmarshal-length-prefix-coder-from-v-want-a-single","errorCode":null,"errorMessage":"could not unmarshal length prefix coder from %v, want a single sub component but have %d","messagePattern":"could not unmarshal length prefix coder from (.+?), want a single sub component but have (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/coder.go","lineNumber":261,"sourceCode":"\n\t\t\t\tt := typex.New(typex.CoGBKType, append([]typex.FullType{key.T}, coder.Types(values)...)...)\n\t\t\t\treturn &coder.Coder{Kind: coder.CoGBK, T: t, Components: append([]*coder.Coder{key}, values...)}, nil\n\t\t\t}\n\t\t\t// It's valid to have a KV<k,Iter<v>> without being a CoGBK, and validating if we need to change to\n\t\t\t// a CoGBK is done at the DataSource, since that's when we can check against the downstream nodes.\n\t\t}\n\n\t\tvalue, err := b.Coder(id)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tt := typex.New(typex.KVType, key.T, value.T)\n\t\treturn &coder.Coder{Kind: coder.KV, T: t, Components: []*coder.Coder{key, value}}, nil\n\n\tcase urnLengthPrefixCoder:\n\t\tif len(components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"could not unmarshal length prefix coder from %v, want a single sub component but have %d\", c, len(components))\n\t\t}\n\n\t\tsub, err := b.peek(components[0])\n\t\tif err != nil {\n\t\t\treturn nil, errors.Errorf(\"could not unmarshal length prefix coder component: %w\", err)\n\t\t}\n\n\t\t// No payload means this coder was length prefixed by the runner\n\t\t// but is likely self describing - AKA a beam coder.\n\t\t// if len(sub.GetSpec().GetPayload()) == 0 {\n\t\t// \treturn b.makeCoder(components[0], sub)\n\t\t// }\n\t\t// TODO(lostluck) 2018/10/17: Make this strict again, once dataflow can use\n\t\t// the portable pipeline model directly (BEAM-2885)\n\t\tswitch u := sub.GetSpec().GetUrn(); u {\n\t\tcase \"\", urnCustomCoder:\n\t\t\tvar ref v1pb.CustomCoder\n\t\t\tif err := protox.DecodeBase64(string(sub.GetSpec().GetPayload()), &ref); err != nil {","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/coder.go#L243-L279","documentation":"makeCoder handles the length-prefix coder URN and expects exactly one sub-component coder. If the proto declares any other number of components, unmarshaling fails with this error listing the coder proto and actual component count.","triggerScenarios":"makeCoder on beam:coders:length_prefix:v1 where components != 1 — produced by malformed serialization or a non-conformant runner.","commonSituations":"Custom runners wrapping coders with length-prefix incorrectly; corrupted or hand-edited pipeline protos; foreign-language SDK interop emitting wrong arity.","solutions":["Ensure the length-prefix coder in the pipeline proto declares exactly one component coder ID.","Regenerate the pipeline with a standard Beam SDK instead of hand-crafting coders.","Check the runner's coder-expansion logic for bugs when it applies length-prefixing.","Compare with a working pipeline's proto to see the expected coder structure."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if lp := comps.GetCoders()[lpCoderID]; lp != nil && len(lp.GetComponentCoderIds()) != 1 {\n    return fmt.Errorf(\"length-prefix coder %s must have 1 component, has %d\", lpCoderID, len(lp.GetComponentCoderIds()))\n}","typeGuard":null,"tryCatchPattern":"cd, err := um.Coder(id)\nif err != nil && strings.Contains(err.Error(), \"want a single sub component\") {\n    log.Printf(\"malformed length-prefix coder: %v\", err)\n}","preventionTips":["Let the runner/SDK apply length-prefixing rather than hand-building it.","Validate coder arity before submitting custom protos.","Compare against a known-good pipeline proto when debugging runner interop."],"tags":["go","coder","length-prefix","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"}