{"record":{"id":"d8b00fb18e793598","repo":"apache/beam","slug":"invalid-number-of-components-for-kv-v-v","errorCode":null,"errorMessage":"Invalid number of components for KV: %v, %v","messagePattern":"Invalid number of components for KV: (.+?), (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/typex/fulltype.go","lineNumber":127,"sourceCode":"\t\treturn &tree{class, t, nil}\n\tcase Container:\n\t\tswitch t.Kind() {\n\t\tcase reflect.Slice:\n\t\t\tif len(components) == 0 {\n\t\t\t\t// For elements without sub components, we just create with the type, this handles vanilla slices.\n\t\t\t\t// We include the child type as a component for convenience.\n\t\t\t\treturn &tree{class, t, []FullType{New(t.Elem())}}\n\t\t\t}\n\t\t\t// For elements which themselves have components, we need to go deeper.\n\t\t\treturn &tree{class, t, []FullType{New(t.Elem(), components[0].Components()...)}}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"Unexpected aggregate type: %v\", t))\n\t\t}\n\tcase Composite:\n\t\tswitch t {\n\t\tcase KVType:\n\t\t\tif len(components) != 2 {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid number of components for KV: %v, %v\", t, components))\n\t\t\t}\n\t\t\tif isAnyNonKVAndNonWindowedComposite(components) {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composite composites inside KV: %v, %v\", t, components))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase WindowedValueType:\n\t\t\tif len(components) != 1 {\n\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) {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/typex/fulltype.go#L109-L145","documentation":"FullType.New requires exactly two components for a KV composite type; anything else panics. KV is the SDK's composite of exactly key and value FullTypes, so a component count other than 2 is an invalid type construction.","triggerScenarios":"Calling typex.New with class Composite and t == typex.KVType but a components slice whose length is not 2 — e.g. from hand-assembled component lists or helpers that build KV types from unvalidated input.","commonSituations":"Custom code constructing KV FullTypes programmatically; schema/codegen tools emitting the wrong number of components; misuse of typex.New by passing per-element components directly.","solutions":["Ensure exactly two components (key and value FullTypes) when constructing a KV type.","Build KV PCollections via beam.KV or MakeStruct helpers instead of hand-building FullType trees.","Validate component counts before calling typex.New with KVType."],"exampleFix":"// before\ntypex.New(typex.Composite, typex.KVType, keyOnly) // 1 component: panics\n// after\ntypex.New(typex.Composite, typex.KVType, keyFT, valueFT)","handlingStrategy":"validation","validationCode":"if t == typex.KVType && len(components) != 2 {\n\treturn fmt.Errorf(\"KV requires exactly 2 components, got %d\", len(components))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct KV types from a key FullType plus a value FullType.","Prefer beam.KV and high-level transform helpers over manual FullType assembly."],"tags":["go","beam","typex","kv","panic"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}