{"record":{"id":"46710e8f3b729b05","repo":"dgraph-io/badger","slug":"errbadmagic","errorCode":"errBadMagic","errorMessage":"manifest has bad magic","messagePattern":"manifest has bad magic","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"manifest.go","lineNumber":344,"sourceCode":"\tcount   int64\n}\n\nfunc (r *countingReader) Read(p []byte) (n int, err error) {\n\tn, err = r.wrapped.Read(p)\n\tr.count += int64(n)\n\treturn\n}\n\nfunc (r *countingReader) ReadByte() (b byte, err error) {\n\tb, err = r.wrapped.ReadByte()\n\tif err == nil {\n\t\tr.count++\n\t}\n\treturn\n}\n\nvar (\n\terrBadMagic    = errors.New(\"manifest has bad magic\")\n\terrBadChecksum = errors.New(\"manifest has checksum mismatch\")\n)\n\n// ReplayManifestFile reads the manifest file and constructs two manifest objects.  (We need one\n// immutable copy and one mutable copy of the manifest.  Easiest way is to construct two of them.)\n// Also, returns the last offset after a completely read manifest entry -- the file must be\n// truncated at that point before further appends are made (if there is a partial entry after\n// that).  In normal conditions, truncOffset is the file size.\nfunc ReplayManifestFile(fp *os.File, extMagic uint16, opt Options) (Manifest, int64, error) {\n\tr := countingReader{wrapped: bufio.NewReader(fp)}\n\n\tvar magicBuf [8]byte\n\tif _, err := io.ReadFull(&r, magicBuf[:]); err != nil {\n\t\treturn Manifest{}, 0, errBadMagic\n\t}\n\tif !bytes.Equal(magicBuf[0:4], magicText[:]) {\n\t\treturn Manifest{}, 0, errBadMagic\n\t}","sourceCodeStart":326,"sourceCodeEnd":362,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/manifest.go#L326-L362","documentation":"errBadMagic is a sentinel error from ReplayManifestFile indicating the MANIFEST file does not begin with the expected magic text. It fires either when the first 8 bytes cannot be read (io.ReadFull fails — a truncated or empty file) or when bytes 0:4 do not equal magicText, meaning the file is not a Badger MANIFEST at all or is corrupted at offset 0. It signals on-disk metadata corruption, not a runtime condition.","triggerScenarios":"Thrown at manifest.go:344 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the directory actually contains a Badger database (a MANIFEST file) and that the path passed to badger.Open is correct","Restore the MANIFEST from a backup snapshot if one exists","If the file is truncated (read failure of the 8-byte header), try truncating/removing the damaged MANIFEST so Badger recreates it, accepting that LSM table bookkeeping is rebuilt from the existing .vlog/SST files per the troubleshooting guide","If data is expendable, delete the whole database directory and let Badger create a fresh one"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}