{"record":{"id":"52700b579b124fbf","repo":"apache/beam","slug":"params-batchsizebytes-must-be-0-got-d","errorCode":null,"errorMessage":"Params.BatchSizeBytes must be >= 0; got %d","messagePattern":"Params\\.BatchSizeBytes must be >= 0; got (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/batch/batch.go","lineNumber":186,"sourceCode":"\n\t// BatchSizeBytes is the target maximum cumulative byte size per\n\t// batch. A batch is emitted as soon as adding another element\n\t// would exceed BatchSizeBytes. Zero disables the byte-based\n\t// trigger.\n\tBatchSizeBytes int64\n\n\t// MaxBufferingDuration, when > 0, triggers emission of a partial\n\t// batch after this much processing time has elapsed since the\n\t// first element of the current batch was buffered.\n\tMaxBufferingDuration time.Duration\n}\n\nfunc (p Params) validate() error {\n\tif p.BatchSize < 0 {\n\t\treturn fmt.Errorf(\"Params.BatchSize must be >= 0; got %d\", p.BatchSize)\n\t}\n\tif p.BatchSizeBytes < 0 {\n\t\treturn fmt.Errorf(\"Params.BatchSizeBytes must be >= 0; got %d\", p.BatchSizeBytes)\n\t}\n\tif p.BatchSize == 0 && p.BatchSizeBytes == 0 {\n\t\treturn fmt.Errorf(\"Params: at least one of BatchSize or BatchSizeBytes must be > 0\")\n\t}\n\tif p.MaxBufferingDuration < 0 {\n\t\treturn fmt.Errorf(\"Params.MaxBufferingDuration must be >= 0; got %s\", p.MaxBufferingDuration)\n\t}\n\treturn nil\n}\n\nconst (\n\tsizerNone      int32 = 0\n\tsizerPrimitive int32 = 1\n)\n\n// codecCache keeps a per-value-type ElementEncoder/Decoder pair.\ntype codecCache struct {\n\tonce sync.Once","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/batch/batch.go#L168-L204","documentation":"GroupIntoBatches validates Params.BatchSizeBytes, the byte-size threshold per batch, and requires it to be non-negative. Negative values are treated as invalid configuration and rejected before the pipeline runs.","triggerScenarios":"Passing batch.Params with a negative BatchSizeBytes (e.g. -1024) to GroupIntoBatches or GroupIntoBatchesWithShardedKey.","commonSituations":"Computing byte limits from a signed config that went negative, typos in defaults, or misreading MaxBufferingDuration as a byte field and negating it.","solutions":["Set BatchSizeBytes to a non-negative value (0 is allowed if BatchSize > 0)","Validate limits at config load time before constructing Params","Check the sign of computed byte budgets (e.g. total - overhead can go negative)"],"exampleFix":"// before\np := batch.Params{BatchSizeBytes: budget - overhead} // can be negative\n// after\nbs := budget - overhead\nif bs < 0 { bs = 0 }\np := batch.Params{BatchSizeBytes: bs}","handlingStrategy":"validation","validationCode":"if p.BatchSizeBytes < 0 { return errors.New(\"BatchSizeBytes must be >= 0\") } // before calling GroupIntoBatches","typeGuard":null,"tryCatchPattern":"if err := p.Validate(); err != nil {\n    return fmt.Errorf(\"invalid batch params: %w\", err)\n}","preventionTips":["Guard computed byte budgets (budget - overhead) against negatives","Validate limits when loading configuration","Set positive defaults instead of leaving zero-value fields","Add unit tests for param validation"],"tags":["go","batching","validation","config"],"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-20T03:17:13.778Z"}