{"record":{"id":"27822da52984e993","repo":"dgraph-io/badger","slug":"errbannedkey","errorCode":"ErrBannedKey","errorMessage":"Key is using the banned prefix","messagePattern":"Key is using the banned prefix","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"errors.go","lineNumber":47,"sourceCode":"\t// ErrConflict is returned when a transaction conflicts with another transaction. This can\n\t// happen if the read rows had been updated concurrently by another transaction.\n\tErrConflict = stderrors.New(\"Transaction Conflict. Please retry\")\n\n\t// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.\n\tErrReadOnlyTxn = stderrors.New(\"No sets or deletes are allowed in a read-only transaction\")\n\n\t// ErrDiscardedTxn is returned if a previously discarded transaction is reused.\n\tErrDiscardedTxn = stderrors.New(\"This transaction has been discarded. Create a new one\")\n\n\t// ErrEmptyKey is returned if an empty key is passed on an update function.\n\tErrEmptyKey = stderrors.New(\"Key cannot be empty\")\n\n\t// ErrInvalidKey is returned if the key has a special !badger! prefix,\n\t// reserved for internal usage.\n\tErrInvalidKey = stderrors.New(\"Key is using a reserved !badger! prefix\")\n\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","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/errors.go#L29-L65","documentation":"ErrBannedKey is returned when a read/write key belongs to a banned namespace. When WithNamespaceOffset is configured, the uint64 namespace extracted at that offset is checked against db.bannedNamespaces (db.go:1945) and banned namespaces are rejected on both reads and writes.","triggerScenarios":"Any Set/Get/Delete whose key, at opt.NamespaceOffset, encodes a namespace previously registered via db.SetBannedNamespaces; keys shorter than NamespaceOffset+8 may also misbehave in that check.","commonSituations":"Multi-tenant setups banning a tenant's namespace (e.g. after abuse or data deletion) while old application code still sends that tenant's keys.","solutions":["Stop issuing keys for banned namespaces in the application layer","Remove the namespace from the banned list with SetBannedNamespaces if the ban was unintended","Ensure keys are at least NamespaceOffset+8 bytes long so the namespace is read correctly"],"exampleFix":"// before\nkey := makeTenantKey(tenantID, k) // tenantID may be banned\nrerr := txn.Get(key)               // ErrBannedKey\n// after\nif banned[tenantID] {\n    return fmt.Errorf(\"tenant %d is banned\", tenantID)\n}\nrerr := txn.Get(makeTenantKey(tenantID, k))","handlingStrategy":"validation","validationCode":"if len(key) < db.opt.NamespaceOffset+8 {\n    return errors.New(\"key too short to carry namespace\")\n}\nns := binary.BigEndian.Uint64(key[db.opt.NamespaceOffset:])\nif banned.Has(ns) {\n    return fmt.Errorf(\"namespace %d is banned\", ns)\n}","typeGuard":null,"tryCatchPattern":"if _, err := txn.Get(key); err != nil {\n    if errors.Is(err, badger.ErrBannedKey) {\n        return ErrTenantBlocked\n    }\n    return err\n}","preventionTips":["Check the banned-namespace set in the application before touching the DB","Keep keys long enough for NamespaceOffset + 8 bytes","Coordinate bans between ops tooling and application config"],"tags":["badger","validation","namespaces","multi-tenant"],"backgroundTag":"banned-namespace-key","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"}