{"record":{"id":"58c1f06fe8f8bee8","repo":"apache/beam","slug":"batch-size-must-be-greater-than-0","errorCode":null,"errorMessage":"batch size must be greater than 0","messagePattern":"batch size must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/mongodbio/write_option.go","lineNumber":36,"sourceCode":"import (\n\t\"errors\"\n)\n\n// WriteOption represents options for writing to MongoDB.\ntype WriteOption struct {\n\tBatchSize int64\n\tOrdered   bool\n}\n\n// WriteOptionFn is a function that configures a WriteOption.\ntype WriteOptionFn func(option *WriteOption) error\n\n// WithWriteBatchSize configures the WriteOption to use the provided batch size when writing\n// documents.\nfunc WithWriteBatchSize(batchSize int64) WriteOptionFn {\n\treturn func(o *WriteOption) error {\n\t\tif batchSize <= 0 {\n\t\t\treturn errors.New(\"batch size must be greater than 0\")\n\t\t}\n\n\t\to.BatchSize = batchSize\n\t\treturn nil\n\t}\n}\n\n// WithWriteOrdered configures the WriteOption whether to apply an ordered bulk write.\nfunc WithWriteOrdered(ordered bool) WriteOptionFn {\n\treturn func(o *WriteOption) error {\n\t\to.Ordered = ordered\n\t\treturn nil\n\t}\n}\n","sourceCodeStart":18,"sourceCodeEnd":51,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/mongodbio/write_option.go#L18-L51","documentation":"WithWriteBatchSize is a WriteOption for the Beam MongoDB connector controlling how many documents are batched per MongoDB insert. It rejects values <= 0 since batching requires at least one document per batch. The error surfaces when options are applied to WriteOption.","triggerScenarios":"Calling mongodbio.Write with options including mongodbio.WithWriteBatchSize(0) or any negative int64, e.g. from an unset or mis-parsed configuration value.","commonSituations":"Batch size sourced from an environment variable or pipeline option defaulting to 0; a config YAML/JSON field omitted and unmarshaled as zero; confusing batch size with bundle size options.","solutions":["Pass a positive batch size, e.g. mongodbio.WithWriteBatchSize(1000).","Validate the configured value before building options and fall back to a sensible default (e.g. 500-1000 docs).","Fix upstream parsing so omitted config fields yield the default rather than 0."],"exampleFix":"// before\nopts = append(opts, mongodbio.WithWriteBatchSize(batchSize)) // batchSize = 0\n// after\nif batchSize <= 0 {\n    batchSize = 1000\n}\nopts = append(opts, mongodbio.WithWriteBatchSize(batchSize))","handlingStrategy":"validation","validationCode":"if batchSize <= 0 {\n    return fmt.Errorf(\"batchSize must be > 0, got %d\", batchSize)\n}\nopts = append(opts, mongodbio.WithWriteBatchSize(batchSize))","typeGuard":null,"tryCatchPattern":"if err := applyOptions(writeOpts...); err != nil {\n    return fmt.Errorf(\"mongodbio write options invalid: %w\", err)\n}","preventionTips":["Default batch size to a positive value (e.g. 1000) in config loading.","Fail fast at CLI/env parsing when numeric options are zero.","Add config schema checks that numeric fields have minimum: 1."],"tags":["go","apache-beam","mongodb","config-validation"],"backgroundTag":"invalid-config-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}