{"record":{"id":"797d69e131095cf6","repo":"apache/beam","slug":"shardedkey-coder-requires-exactly-1-component-key-got-d","errorCode":null,"errorMessage":"ShardedKey coder requires exactly 1 component (key), got %d","messagePattern":"ShardedKey coder requires exactly 1 component \\(key\\), got (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/graphx/coder.go","lineNumber":513,"sourceCode":"\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.\n\n\t\t\tunion := b.internBuiltInCoder(urnCoGBKList, comp[1:]...)\n\t\t\tvalue = b.internBuiltInCoder(urnLengthPrefixCoder, union)\n\t\t}\n\n\t\t// SDKs always provide iterableCoder to runners, but can receive StateBackedIterables in return.\n\t\tstream := b.internBuiltInCoder(urnIterableCoder, value)\n\t\treturn b.internBuiltInCoder(urnKVCoder, comp[0], stream), nil\n\n\tcase coder.ShardedKey:\n\t\tcomp, err := b.AddMulti(c.Components)\n\t\tif err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal ShardedKey coder %v\", c)\n\t\t}\n\t\tif len(comp) != 1 {\n\t\t\treturn \"\", errors.Errorf(\"ShardedKey coder requires exactly 1 component (key), got %d\", len(comp))\n\t\t}\n\t\treturn b.internBuiltInCoder(urnShardedKeyCoder, comp...), nil\n\n\tcase coder.WindowedValue:\n\t\tcomp := []string{}\n\t\tif ids, err := b.AddMulti(c.Components); err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal window coder %v\", c)\n\t\t} else {\n\t\t\tcomp = append(comp, ids...)\n\t\t}\n\t\tif id, err := b.AddWindowCoder(c.Window); err != nil {\n\t\t\treturn \"\", errors.Wrapf(err, \"failed to marshal window coder %v\", c)\n\t\t} else {\n\t\t\tcomp = append(comp, id)\n\t\t}\n\t\treturn b.internBuiltInCoder(urnWindowedValueCoder, comp...), nil\n\n\tcase coder.Bytes:","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/graphx/coder.go#L495-L531","documentation":"A coder.ShardedKey was declared with a component count other than exactly 1 during marshalling. ShardedKey coders by definition carry only the key component, so 0 or 2+ components is a structural invariant violation.","triggerScenarios":"Constructing a coder.ShardedKey with an empty or multi-element Components slice and passing it to CoderBuilder.Add; programmatic coder construction with wrong arity.","commonSituations":"Custom pipeline-construction code or cross-language expansion producing ShardedKey coders with wrong component counts; manual coder assembly bugs.","solutions":["Fix the coder construction so ShardedKey has exactly one component: coder.NewShardedKey(keyType)","Check code that builds coders programmatically for wrong arity","Verify the expansion/transform producing this coder emits a single-component ShardedKey","Upgrade the SDK if a transform generates the malformed coder"],"exampleFix":"// before\nc := &coder.Coder{Kind: coder.ShardedKey, Components: []*coder.Coder{key, value}}\n// after\nc := &coder.Coder{Kind: coder.ShardedKey, Components: []*coder.Coder{key}}","handlingStrategy":"validation","validationCode":"// Guard coder construction before calling Add\nfunc validShardedKey(c *coder.Coder) bool {\n    return c.Kind != coder.ShardedKey || len(c.Components) == 1\n}","typeGuard":"func isShardedKey(c *coder.Coder) bool { return c != nil && c.Kind == coder.ShardedKey && len(c.Components) == 1 }","tryCatchPattern":null,"preventionTips":["Use coder.NewShardedKey helpers instead of struct literals","Never add extra components to ShardedKey coders","Assert component arity in custom pipeline-construction code"],"tags":["beam","go","coder","arity"],"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"}