dgraph-io/badger · error
ErrInvalidRequest
ErrInvalidRequest
Error message
Invalid request
What it means
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.
Source
Thrown at errors.go:63
// ErrBannedKey is returned if the read/write key belongs to any banned namespace.
ErrBannedKey = stderrors.New("Key is using the banned prefix")
// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
// In such a case, GC can't be run.
ErrThresholdZero = stderrors.New(
"Value log GC can't run because threshold is set to zero")
// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
ErrNoRewrite = stderrors.New(
"Value log GC attempt didn't result in any cleanup")
// ErrRejected is returned if a value log GC is called either while another GC is running, or
// after DB::Close has been called.
ErrRejected = stderrors.New("Value log GC request rejected")
// ErrInvalidRequest is returned if the user request is invalid.
ErrInvalidRequest = stderrors.New("Invalid request")
// ErrManagedTxn is returned if the user tries to use an API which isn't
// allowed due to external management of transactions, when using ManagedDB.
ErrManagedTxn = stderrors.New(
"Invalid API request. Not allowed to perform this action using ManagedDB")
// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when
// NamespaceOffset is non-negative.
ErrNamespaceMode = stderrors.New(
"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.")
// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
ErrInvalidDump = stderrors.New("Data dump cannot be read")
// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
ErrZeroBandwidth = stderrors.New("Bandwidth must be greater than zero")
// ErrWindowsNotSupported is returned when opt.ReadOnly is used on WindowsView on GitHub (pinned to 2a001d466f)
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
Example fix
// before
db.RunValueLogGC(ratio) // ratio may be 0
// after
if ratio <= 0.0 || ratio >= 1.0 {
ratio = 0.5
}
db.RunValueLogGC(ratio) Defensive patterns
Strategy: validation
Validate before calling
if discardRatio <= 0.0 || discardRatio >= 1.0 { return fmt.Errorf("invalid discardRatio %v: must be in (0,1)", discardRatio) } Try / catch
if err := db.RunValueLogGC(ratio); err != nil {
if errors.Is(err, ErrInvalidRequest) { ratio = 0.5; return db.RunValueLogGC(ratio) }
return err
} Prevention
- 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
When it happens
Trigger: db.RunValueLogGC(0), db.RunValueLogGC(1), db.RunValueLogGC(-0.5) — any discardRatio >= 1.0 or <= 0.0 passed at db.go:1312.
Common situations: 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.
Understand the failure class
Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.
Related errors
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/d6ee081297c2f4ec.
Report an issue: GitHub.