dgraph-io/badger · error
ErrNamespaceMode
ErrNamespaceMode
Error message
Invalid API request. Not allowed to perform this action when NamespaceMode is not set.
What it means
ErrNamespaceMode is returned when an API that requires namespace support (NamespaceOffset >= 0) is called on a DB opened without it. BanNamespace and related namespace APIs are only valid when WithNamespaceOffset was configured at Open time. Defined in errors.go.
Source
Thrown at errors.go:72
// 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 Windows
ErrWindowsNotSupported = stderrors.New("Read-only mode is not supported on Windows")
// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9
ErrPlan9NotSupported = stderrors.New("Read-only mode is not supported on Plan 9")
// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
// corrupt data to allow Badger to run properly.
ErrTruncateNeeded = stderrors.New(
"Log truncate required to run DB. This might result in data loss")View on GitHub (pinned to 2a001d466f)
Solutions
- Open the DB with badger.WithNamespaceOffset(offset) before using namespace APIs
- Remove or gate the BanNamespace call if namespaces are not used
- Check opt.NamespaceOffset before invoking namespace APIs
Example fix
// before db.BanNamespace(3) // after opts = append(opts, badger.WithNamespaceOffset(2)) db, err := badger.Open(opts...) // ... db.BanNamespace(3)
Defensive patterns
Strategy: validation
Validate before calling
if db.Opts().NamespaceOffset < 0 { return ErrNamespaceModePrecheck } Type guard
func namespacesEnabled(db *DB) bool { return db.Opts().NamespaceOffset >= 0 } Try / catch
if err := db.BanNamespace(ns); err != nil {
if errors.Is(err, ErrNamespaceMode) { /* namespaces not enabled */ }
} Prevention
- Always pair namespace API usage with WithNamespaceOffset at Open
- Feature-flag namespace code paths on the Open config
- Test Open options in CI for each deployment profile
When it happens
Trigger: Calling db.BanNamespace(ns) (db.go:1953) or other namespace-restricted APIs when db.opt.NamespaceOffset < 0, i.e. the DB was opened without WithNamespaceOffset.
Common situations: Copying namespace-based code into an app whose Open options never enabled namespaces; environment-specific configs that omit the namespace option; upgrading Badger and adopting namespace features without changing Open options.
Related errors
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/ec466de03fcebec3.
Report an issue: GitHub.