{"record":{"id":"ec466de03fcebec3","repo":"dgraph-io/badger","slug":"errnamespacemode","errorCode":"ErrNamespaceMode","errorMessage":"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.","messagePattern":"Invalid API request\\. Not allowed to perform this action when NamespaceMode is not set\\.","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":72,"sourceCode":"\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\n\tErrWindowsNotSupported = stderrors.New(\"Read-only mode is not supported on Windows\")\n\n\t// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9\n\tErrPlan9NotSupported = stderrors.New(\"Read-only mode is not supported on Plan 9\")\n\n\t// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of\n\t// corrupt data to allow Badger to run properly.\n\tErrTruncateNeeded = stderrors.New(\n\t\t\"Log truncate required to run DB. This might result in data loss\")","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndb.BanNamespace(3)\n// after\nopts = append(opts, badger.WithNamespaceOffset(2))\ndb, err := badger.Open(opts...)\n// ...\ndb.BanNamespace(3)","handlingStrategy":"validation","validationCode":"if db.Opts().NamespaceOffset < 0 { return ErrNamespaceModePrecheck }","typeGuard":"func namespacesEnabled(db *DB) bool { return db.Opts().NamespaceOffset >= 0 }","tryCatchPattern":"if err := db.BanNamespace(ns); err != nil {\n\tif errors.Is(err, ErrNamespaceMode) { /* namespaces not enabled */ }\n}","preventionTips":["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"],"tags":["badger","namespace","configuration","api-misuse"],"backgroundTag":"feature-not-enabled","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"}