{"record":{"id":"105a8707a6aff8c8","repo":"dgraph-io/badger","slug":"while-setting-banned-keys-w","errorCode":null,"errorMessage":"While setting banned keys: %w","messagePattern":"While setting banned keys: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"db.go","lineNumber":394,"sourceCode":"\tdb.orc.nextTxnTs = db.MaxVersion()\n\tdb.opt.Infof(\"Set nextTxnTs to %d\", db.orc.nextTxnTs)\n\n\tif err = db.vlog.open(db); err != nil {\n\t\treturn db, y.Wrapf(err, \"During db.vlog.open\")\n\t}\n\n\t// Let's advance nextTxnTs to one more than whatever we observed via\n\t// replaying the logs.\n\tdb.orc.txnMark.Done(db.orc.nextTxnTs)\n\t// In normal mode, we must update readMark so older versions of keys can be removed during\n\t// compaction when run in offline mode via the flatten tool.\n\tdb.orc.readMark.Done(db.orc.nextTxnTs)\n\tdb.orc.incrementNextTs()\n\n\tgo db.threshold.listenForValueThresholdUpdate()\n\n\tif err := db.initBannedNamespaces(); err != nil {\n\t\treturn db, fmt.Errorf(\"While setting banned keys: %w\", err)\n\t}\n\n\tdb.closers.writes = z.NewCloser(1)\n\tgo db.doWrites(db.closers.writes)\n\n\tif !db.opt.InMemory && !db.opt.ReadOnly {\n\t\tdb.closers.valueGC = z.NewCloser(1)\n\t\tgo db.vlog.waitOnGC(db.closers.valueGC)\n\t}\n\n\tdb.closers.pub = z.NewCloser(1)\n\tgo db.pub.listenForUpdates(db.closers.pub)\n\n\tvalueDirLockGuard = nil\n\tdirLockGuard = nil\n\tmanifestFile = nil\n\treturn db, nil\n}","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/db.go#L376-L412","documentation":"During Open, badger initializes banned namespaces (reserved key prefixes) from disk. If that step fails, Open wraps the underlying error with \"While setting banned keys: %w\", meaning the DB could not be set up safely and startup is aborted.","triggerScenarios":"Calling badger.Open on a directory whose key-registry/banned-namespace files are unreadable, corrupted, or not writable during initBannedNamespaces().","commonSituations":"Corrupted or partially deleted DB directory; permission problems on the data dir; restoring a directory missing internal files; disk I/O failures.","solutions":["Inspect the wrapped error (%w) for the root cause (permissions vs corruption)","Fix permissions so the DB user can read/write the data directory","Restore from backup if internal files are corrupted","If the directory is disposable, remove it and reopen to start fresh"],"exampleFix":"// before\ndb, err := badger.Open(opt) // err: While setting banned keys: ...\n// after\nif err != nil {\n    if os.IsPermission(errors.Unwrap(err)) { fixPermissions(dir) }\n    return err // or restore from backup\n}","handlingStrategy":"try-catch","validationCode":"if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"badger dir unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"db, err := badger.Open(opt)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) { /* fix perms/path */ }\n    log.Fatalf(\"open failed: %v\", err) // inspect errors.Unwrap\n}","preventionTips":["Verify the data dir is readable/writable by the DB user before Open","Keep backups of the badger directory","Never delete individual internal files from a live DB","Run Open under a supervisor that surfaces wrapped root causes"],"tags":["badger","open","io","corruption"],"backgroundTag":"database-open-failed","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"}