{"id":"33dc8ec2aa9822a2","repo":"go-redis/redis","slug":"redis-autopipelineoptions-maxbatchbytes-d-must-b","errorCode":null,"errorMessage":"redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0","messagePattern":"redis: AutoPipelineOptions\\.MaxBatchBytes=(.+?) must be >= 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"autopipeline.go","lineNumber":228,"sourceCode":"// Validate()==nil does not guarantee construction succeeds: rules that need\n// the face (e.g. NumShards>1 requires Unordered on the deferred face) are\n// enforced by the AutoPipeline/AsyncAutoPipeline getters. Note also that\n// Options.AutoPipelineOptions is validated lazily — on the first getter\n// call, not in NewClient.\nfunc (cfg *AutoPipelineOptions) Validate() error {\n\tif cfg.MaxConcurrentBatches > 1 && !cfg.Unordered {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxConcurrentBatches=%d requires Unordered:true \"+\n\t\t\t\"(parallel batches do not preserve command ordering); set Unordered:true to allow it, \"+\n\t\t\t\"or keep MaxConcurrentBatches=1 for an ordered stream\", cfg.MaxConcurrentBatches)\n\t}\n\t// Reject obviously-wrong negatives so a typo surfaces at construction rather\n\t// than being silently coerced to a default. Zero is allowed and means \"use\n\t// the default\" (MaxBatchSize) or \"no delay\" (MaxFlushDelay).\n\tif cfg.MaxBatchSize < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxBatchSize=%d must be >= 0\", cfg.MaxBatchSize)\n\t}\n\tif cfg.MaxBatchBytes < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxBatchBytes=%d must be >= 0\", cfg.MaxBatchBytes)\n\t}\n\tif cfg.MaxConcurrentBatches < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxConcurrentBatches=%d must be >= 0\", cfg.MaxConcurrentBatches)\n\t}\n\tif cfg.MaxFlushDelay < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.MaxFlushDelay=%s must be >= 0\", cfg.MaxFlushDelay)\n\t}\n\tif cfg.NumShards < 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.NumShards=%d must be >= 0\", cfg.NumShards)\n\t}\n\tif cfg.AdaptiveDelay && cfg.MaxFlushDelay <= 0 {\n\t\treturn fmt.Errorf(\"redis: AutoPipelineOptions.AdaptiveDelay requires MaxFlushDelay > 0 \" +\n\t\t\t\"(adaptive delay scales MaxFlushDelay by queue fill; with no MaxFlushDelay it would \" +\n\t\t\t\"silently disable batch accumulation entirely)\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/autopipeline.go#L210-L246","documentation":"Returned by AutoPipelineOptions.Validate when MaxBatchBytes is negative. Zero is allowed (meaning no byte cap); negative values are rejected as configuration errors. MaxBatchBytes caps a batch by approximate payload volume to avoid huge single writes.","triggerScenarios":"Setting AutoPipelineOptions.MaxBatchBytes to a negative value. Sign errors or uninitialized config fields producing negatives.","commonSituations":"Config parsing mistakes. Using a negative sentinel to mean 'disabled' when zero is the documented disabled value. Arithmetic underflow.","solutions":["Set MaxBatchBytes to 0 (no byte cap, the default) or a positive byte limit.","Use 0 rather than a negative for 'disabled'.","Sanitize config values before constructing the options."],"exampleFix":"// before\ncfg := &redis.AutoPipelineOptions{MaxBatchBytes: -1024}\n// cfg.Validate() => error\n\n// after\ncfg := &redis.AutoPipelineOptions{MaxBatchBytes: 0}       // no cap\n// or\ncfg := &redis.AutoPipelineOptions{MaxBatchBytes: 1 << 20} // 1 MiB cap","handlingStrategy":"validation","validationCode":"func sanitizeBatchBytes(n int) int {\n    if n < 0 {\n        return 0 // no byte cap instead of an invalid negative\n    }\n    return n\n}","typeGuard":null,"tryCatchPattern":"if err := cfg.Validate(); err != nil {\n    if strings.Contains(err.Error(), \"MaxBatchBytes\") {\n        cfg.MaxBatchBytes = 0 // reset to no-cap\n    }\n}","preventionTips":["Use 0 for 'no byte cap' MaxBatchBytes, never a negative.","Sanitize config values to >= 0 at load time.","Document 0 as the disabled sentinel in your config schema."],"tags":["autopipeline","validation","configuration","value-error"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}