{"record":{"id":"d6ee081297c2f4ec","repo":"dgraph-io/badger","slug":"errinvalidrequest","errorCode":"ErrInvalidRequest","errorMessage":"Invalid request","messagePattern":"Invalid request","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":63,"sourceCode":"\n\t// ErrBannedKey is returned if the read/write key belongs to any banned namespace.\n\tErrBannedKey = stderrors.New(\"Key is using the banned prefix\")\n\n\t// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.\n\t// In such a case, GC can't be run.\n\tErrThresholdZero = stderrors.New(\n\t\t\"Value log GC can't run because threshold is set to zero\")\n\n\t// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.\n\tErrNoRewrite = stderrors.New(\n\t\t\"Value log GC attempt didn't result in any cleanup\")\n\n\t// ErrRejected is returned if a value log GC is called either while another GC is running, or\n\t// after DB::Close has been called.\n\tErrRejected = stderrors.New(\"Value log GC request rejected\")\n\n\t// ErrInvalidRequest is returned if the user request is invalid.\n\tErrInvalidRequest = stderrors.New(\"Invalid request\")\n\n\t// ErrManagedTxn is returned if the user tries to use an API which isn't\n\t// allowed due to external management of transactions, when using ManagedDB.\n\tErrManagedTxn = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action using ManagedDB\")\n\n\t// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when\n\t// NamespaceOffset is non-negative.\n\tErrNamespaceMode = stderrors.New(\n\t\t\"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.\")\n\n\t// ErrInvalidDump if a data dump made previously cannot be loaded into the database.\n\tErrInvalidDump = stderrors.New(\"Data dump cannot be read\")\n\n\t// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.\n\tErrZeroBandwidth = stderrors.New(\"Bandwidth must be greater than zero\")\n\n\t// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L45-L81","documentation":"ErrInvalidRequest is returned when the arguments to an API call are invalid — most commonly when RunValueLogGC is given a discardRatio that is not in the open interval (0.0, 1.0). Badger validates the ratio up front (db.go:1312) and rejects the request. Defined in errors.go as a sentinel error.","triggerScenarios":"db.RunValueLogGC(0), db.RunValueLogGC(1), db.RunValueLogGC(-0.5) — any discardRatio >= 1.0 or <= 0.0 passed at db.go:1312.","commonSituations":"Passing 0 thinking it means 'no minimum'; using a percentage (50) instead of a fraction (0.5); computing the ratio dynamically and getting a divide-by-zero or degenerate value.","solutions":["Clamp or validate discardRatio to 0 < ratio < 1 before calling RunValueLogGC","Use a sane default like 0.5 if the value is computed at runtime","Check units: the ratio is a fraction, not a percent"],"exampleFix":"// before\ndb.RunValueLogGC(ratio) // ratio may be 0\n// after\nif ratio <= 0.0 || ratio >= 1.0 {\n\tratio = 0.5\n}\ndb.RunValueLogGC(ratio)","handlingStrategy":"validation","validationCode":"if discardRatio <= 0.0 || discardRatio >= 1.0 { return fmt.Errorf(\"invalid discardRatio %v: must be in (0,1)\", discardRatio) }","typeGuard":null,"tryCatchPattern":"if err := db.RunValueLogGC(ratio); err != nil {\n\tif errors.Is(err, ErrInvalidRequest) { ratio = 0.5; return db.RunValueLogGC(ratio) }\n\treturn err\n}","preventionTips":["Validate ratios are fractions in (0,1), not percentages","Clamp dynamically computed ratios before calling the API","Write unit tests for boundary values 0 and 1"],"tags":["badger","validation","arguments","garbage-collection"],"backgroundTag":"invalid-argument","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}