{"record":{"id":"a175260a5b6a6268","repo":"apache/beam","slug":"invalid-number-of-components-for-shardedkey-v-v","errorCode":null,"errorMessage":"Invalid number of components for ShardedKey: %v, %v","messagePattern":"Invalid number of components for ShardedKey: (.+?), (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/typex/fulltype.go","lineNumber":153,"sourceCode":"\t\t\t\tpanic(\"Invalid number of components for WindowedValue\")\n\t\t\t}\n\t\t\tif components[0].Type() == WindowedValueType {\n\t\t\t\tpanic(\"Invalid to nest WindowedValue\")\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase CoGBKType:\n\t\t\tif len(components) < 2 {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid number of components for CoGBK: %v\", t))\n\t\t\t}\n\t\t\tif isAnyNonKVComposite(components) {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composites inside CoGBK: %v\", t))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase TimersType:\n\t\t\treturn &tree{class, t, components}\n\t\tcase ShardedKeyType:\n\t\t\tif len(components) != 1 {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid number of components for ShardedKey: %v, %v\", t, components))\n\t\t\t}\n\t\t\tif components[0].Class() == Composite {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composite inside ShardedKey: %v, %v\", t, components))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"Unexpected composite type: %v\", t))\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Invalid underlying type: %v\", t))\n\t}\n}\n\n// NOTE(herohde) 1/26/2018: we allow nested KV types and coders to support the\n// CoGBK translation (using KV<K,KV<int,[]byte>> to encode keyed raw union values)\n// and potentially other uses. We do not have a reasonable way to emit nested KV\n// values, so user functions are still limited to non-nested KVs. Universally-typed\n// KV-values might be simple to allow, for example.","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/typex/fulltype.go#L135-L171","documentation":"typex.New validates ShardedKey types: a ShardedKey must have exactly one component. When len(components) != 1, New panics with this message including the type and its components. The SDK uses this to guarantee the internal invariant that ShardedKey always carries a single underlying value type.","triggerScenarios":"Calling typex.New with a Composite of class ShardedKeyType and zero or two-plus components, e.g. typex.New(typex.ShardedKeyType) or typex.New(typex.ShardedKeyType, t1, t2). Reached via New's public callers: Prefix, CoGroupByKey, CombinePerKey, CombineGlobally, Flatten, GroupByKey.","commonSituations":"Hand-constructing sharded-key types for use with WithShardedKey-style transforms and accidentally passing the key and value separately instead of a single KV component; copy-paste from KV construction code that takes multiple components.","solutions":["Pass exactly one component: typex.New(typex.ShardedKeyType, singleType).","If you intended a keyed pair, wrap the pair in a KV first: typex.New(typex.ShardedKeyType, typex.NewKV(k, v)) is still one component.","If you meant a multi-component composite, use a different type class (e.g. CoGBK or a struct-based type) instead of ShardedKey."],"exampleFix":"// before\ntypex.New(typex.ShardedKeyType, keyType, valueType)\n// after\ntypex.New(typex.ShardedKeyType, typex.NewKV(keyType, valueType))","handlingStrategy":"validation","validationCode":"func validShardedKey(cs []typex.FullType) bool { return len(cs) == 1 }","typeGuard":null,"tryCatchPattern":"func safeNew(t typex.Type, cs ...typex.FullType) (ft typex.FullType, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"typex.New: %v\", r) }\n    }()\n    return typex.New(t, cs...), nil\n}","preventionTips":["Remember ShardedKey always takes exactly one component.","Combine key+value into a single KV component if both are needed.","Add a unit test for custom type construction helpers."],"tags":["go","apache-beam","typex","panic","arity-mismatch"],"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"}