{"record":{"id":"6da3700ce49cb682","repo":"nats-io/nats-server","slug":"max-bytes-must-not-be-negative","errorCode":null,"errorMessage":"max_bytes must not be negative","messagePattern":"max_bytes must not be negative","errorType":"validation","errorClass":"ApiError","httpStatus":null,"severity":"error","filePath":"server/consumer.go","lineNumber":646,"sourceCode":"\t\t\treturn NewJSPedanticError(errors.New(\"max_ack_pending must be set to -1\"))\n\t\t}\n\t\tconfig.MaxAckPending = -1\n\t}\n\tif config.MaxRequestBatch < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_batch must not be negative\"))\n\t\t}\n\t\tconfig.MaxRequestBatch = 0\n\t}\n\tif config.MaxRequestExpires < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_expires must not be negative\"))\n\t\t}\n\t\tconfig.MaxRequestExpires = 0\n\t}\n\tif config.MaxRequestMaxBytes < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"max_bytes must not be negative\"))\n\t\t}\n\t\tconfig.MaxRequestMaxBytes = 0\n\t}\n\tif config.Heartbeat < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"idle_heartbeat must not be negative\"))\n\t\t}\n\t\tconfig.Heartbeat = 0\n\t}\n\tif config.InactiveThreshold < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"inactive_threshold must not be negative\"))\n\t\t}\n\t\tconfig.InactiveThreshold = 0\n\t}\n\tif config.PinnedTTL < 0 {\n\t\tif pedantic {\n\t\t\treturn NewJSPedanticError(errors.New(\"priority_timeout must not be negative\"))","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/consumer.go#L628-L664","documentation":"A JetStream pedantic validation error thrown when MaxRequestMaxBytes (the maximum bytes a pull request may request) is negative. Byte counts cannot be negative; in pedantic mode the server rejects the config rather than silently clamping to 0 (server/consumer.go:646).","triggerScenarios":"ConsumerConfig.MaxRequestMaxBytes < 0 supplied on consumer create/update with pedantic validation, e.g. MaxRequestMaxBytes: -1024 or a computed byte budget that went below zero.","commonSituations":"Byte-budget arithmetic (quota - usage) yielding negatives; operators using -1 for 'unlimited' (0 is the correct sentinel here); config templating with negative placeholder values.","solutions":["Set MaxRequestMaxBytes to a positive integer of bytes or 0 for the server default.","Clamp budget computations to >= 0 before assignment.","Replace -1 'unlimited' convention with 0 for this field.","Run Validate(true) client-side before the API call."],"exampleFix":"// before\nbytes := quota - used // -2048\ncc := nats.ConsumerConfig{MaxRequestMaxBytes: bytes}\n// after\nif bytes < 0 { bytes = 0 }\ncc := nats.ConsumerConfig{MaxRequestMaxBytes: bytes}","handlingStrategy":"validation","validationCode":"if cfg.MaxRequestMaxBytes < 0 { return errors.New(\"max_bytes must not be negative\") }","typeGuard":null,"tryCatchPattern":"if _, err := js.AddConsumer(stream, &cc); err != nil && strings.Contains(err.Error(), \"max_bytes\") {\n    cc.MaxRequestMaxBytes = 0\n    _, err = js.AddConsumer(stream, &cc)\n}","preventionTips":["Clamp byte-budget calculations (quota - usage) to >= 0.","Use 0 as 'default', never -1, for this field.","Add a config-load validation step that rejects negative byte fields."],"tags":["jetstream","consumer-config","validation","pull-consumer"],"backgroundTag":"invalid-argument-value","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}