{"record":{"id":"3839396def48b69f","repo":"apache/beam","slug":"bad-length-prefix-v","errorCode":null,"errorMessage":"bad length prefix: %+v","messagePattern":"bad length prefix: %\\+v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/dataflow.go","lineNumber":300,"sourceCode":"\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 nullableType:\n\t\tif len(c.Components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"bad nullable: %+v\", c)\n\t\t}\n\n\t\tinner, err := DecodeCoderRef(c.Components[0])\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tt := typex.New(typex.NullableType, inner.T)\n\t\treturn &coder.Coder{Kind: coder.Nullable, T: t, Components: []*coder.Coder{inner}}, nil\n\n\tcase lengthPrefixType:\n\t\tif len(c.Components) != 1 {\n\t\t\treturn nil, errors.Errorf(\"bad length prefix: %+v\", c)\n\t\t}\n\n\t\tsubC := c.Components[0]\n\t\tswitch subC.Type {\n\t\tcase stringType: // Needs special handling if wrapped by dataflow.\n\t\t\treturn coder.NewString(), nil\n\t\tdefault:\n\t\t\treturn decodeDataflowCustomCoder(subC.Type)\n\t\t}\n\n\tcase intervalWindowType:\n\t\treturn coder.NewIntervalWindowCoder(), nil\n\n\tcase windowedValueType:\n\t\tif len(c.Components) != 2 {\n\t\t\treturn nil, errors.Errorf(\"bad windowed value: %+v\", c)\n\t\t}\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/dataflow.go#L282-L318","documentation":"DecodeCoderRef maps length-prefix-type refs (used for bytes/string coders wrapped by Dataflow) back to coders. Such a ref must contain exactly one component; another count means the encoded graph is malformed, so decoding fails with the ref in the message.","triggerScenarios":"Decoding a CoderRef with Type lengthPrefixType whose Components has length != 1 — during deserialization of a pipeline graph or job description produced/corrupted outside the current encoder.","commonSituations":"Pipeline artifacts serialized by a different Beam version with a different length-prefix layout; custom graph rewriters duplicating components; truncated or manually edited proto/json pipelines.","solutions":["Regenerate the pipeline from source so length-prefix coders are re-encoded correctly.","Verify SDK version parity between the tool that produced the graph and the one decoding it.","Check any custom graph mutation passes for component-list edits on bytes/string coders.","Inspect the printed CoderRef to confirm the malformed component count and locate its producer."],"exampleFix":"// before\nref := &graphx.CoderRef{Type: graphx.LengthPrefix, Components: []*graphx.CoderRef{a, b}}\nc, err := graphx.DecodeCoderRef(ref)\n\n// after\nref := &graphx.CoderRef{Type: graphx.LengthPrefix, Components: []*graphx.CoderRef{innerRef}}\nc, err := graphx.DecodeCoderRef(ref)","handlingStrategy":"try-catch","validationCode":"func validLengthPrefixRef(r *graphx.CoderRef) bool {\n\treturn r != nil && r.Type == graphx.LengthPrefix && len(r.Components) == 1\n}","typeGuard":"func isLengthPrefixRef(r *graphx.CoderRef) bool { return r != nil && r.Type == graphx.LengthPrefix && len(r.Components) == 1 }","tryCatchPattern":"c, err := graphx.DecodeCoderRef(ref)\nif err != nil {\n\tif strings.Contains(err.Error(), \"bad length prefix\") {\n\t\treturn nil, fmt.Errorf(\"corrupt length-prefix coder ref %v: %w\", ref, err)\n\t}\n\treturn nil, err\n}","preventionTips":["Ensure bytes/string coders are encoded by the same SDK that decodes them","Avoid custom tools that duplicate coder components","Validate pipeline protos against the expected schema before decoding"],"tags":["go","beam","coder-deserialization","length-prefix"],"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"}