{"record":{"id":"db9dc46f8f6547a4","repo":"apache/beam","slug":"sourceconfig-numelements-must-be-1-got-v","errorCode":null,"errorMessage":"SourceConfig.NumElements must be >= 1. Got: %v","messagePattern":"SourceConfig\\.NumElements must be >= 1\\. Got: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/synthetic/source.go","lineNumber":260,"sourceCode":"}\n\n// HotKeyFraction determines the value of hot key fraction.\n//\n// Valid values are floating point numbers from 0 to 1.\nfunc (b *SourceConfigBuilder) HotKeyFraction(val float64) *SourceConfigBuilder {\n\tb.cfg.HotKeyFraction = val\n\treturn b\n}\n\n// Build constructs the SourceConfig initialized by this builder. It also\n// performs error checking on the fields, and panics if any have been set to\n// invalid values.\nfunc (b *SourceConfigBuilder) Build() SourceConfig {\n\tif b.cfg.InitialSplits <= 0 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.InitialSplits must be >= 1. Got: %v\", b.cfg.InitialSplits))\n\t}\n\tif b.cfg.NumElements <= 0 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.NumElements must be >= 1. Got: %v\", b.cfg.NumElements))\n\t}\n\tif b.cfg.KeySize <= 0 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.KeySize must be >= 1. Got: %v\", b.cfg.KeySize))\n\t}\n\tif b.cfg.ValueSize <= 0 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.ValueSize must be >= 1. Got: %v\", b.cfg.ValueSize))\n\t}\n\tif b.cfg.NumHotKeys < 0 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.NumHotKeys must be >= 0. Got: %v\", b.cfg.HotKeyFraction))\n\t}\n\tif b.cfg.HotKeyFraction < 0 || b.cfg.HotKeyFraction > 1 {\n\t\tpanic(fmt.Sprintf(\"SourceConfig.HotKeyFraction must be a floating point number from 0 and 1. Got: %v\", b.cfg.NumHotKeys))\n\t}\n\treturn b.cfg\n}\n\n// BuildFromJSON constructs the SourceConfig by populating it with the parsed\n// JSON. Panics if there is an error in the syntax of the JSON or if the input","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/synthetic/source.go#L242-L278","documentation":"Panic raised by the synthetic source config builder's Build when cfg.NumElements is zero or negative. The synthetic source must know how many elements to generate per split; Build validates all numeric knobs up front and fails fast on invalid values rather than misbehaving at runtime.","triggerScenarios":"Building a SourceConfig without NumElements(n) or with NumElements(0) / negative, often when the count comes from an unset flag or computed value.","commonSituations":"Load-test scripts where element count is parameterized and the parameter defaults to 0, or tests that only set KeySize/ValueSize.","solutions":["Call builder.NumElements(n) with n >= 1 before Build().","Default a zero computed element count to a sane positive value.","Validate the element-count config field before constructing the pipeline."],"exampleFix":"// before\nnum := flags.Int(\"num\", 0, \"elements\")\ncfg := synthetic.NewSourceConfig().NumElements(*num).InitialSplits(2).KeySize(8).ValueSize(8).Build()\n// after\nif *num <= 0 {\n    *num = 1000\n}\ncfg := synthetic.NewSourceConfig().NumElements(*num).InitialSplits(2).KeySize(8).ValueSize(8).Build()","handlingStrategy":"validation","validationCode":"if numElements < 1 {\n    return fmt.Errorf(\"synthetic NumElements must be >= 1, got %d\", numElements)\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        err = fmt.Errorf(\"invalid synthetic source config: %v\", r)\n    }\n}()","preventionTips":["Give element-count flags non-zero defaults.","Validate the full SourceConfig field set before calling Build().","Keep builder chains complete; copy from a canonical example."],"tags":["go","apache-beam","synthetic-source","validation"],"backgroundTag":"value-out-of-range","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"}