dgraph-io/badger · error

errBadMagic

errBadMagic

Error message

manifest has bad magic

What it means

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.

Source

Thrown at manifest.go:344

	count   int64
}

func (r *countingReader) Read(p []byte) (n int, err error) {
	n, err = r.wrapped.Read(p)
	r.count += int64(n)
	return
}

func (r *countingReader) ReadByte() (b byte, err error) {
	b, err = r.wrapped.ReadByte()
	if err == nil {
		r.count++
	}
	return
}

var (
	errBadMagic    = errors.New("manifest has bad magic")
	errBadChecksum = errors.New("manifest has checksum mismatch")
)

// ReplayManifestFile reads the manifest file and constructs two manifest objects.  (We need one
// immutable copy and one mutable copy of the manifest.  Easiest way is to construct two of them.)
// Also, returns the last offset after a completely read manifest entry -- the file must be
// truncated at that point before further appends are made (if there is a partial entry after
// that).  In normal conditions, truncOffset is the file size.
func ReplayManifestFile(fp *os.File, extMagic uint16, opt Options) (Manifest, int64, error) {
	r := countingReader{wrapped: bufio.NewReader(fp)}

	var magicBuf [8]byte
	if _, err := io.ReadFull(&r, magicBuf[:]); err != nil {
		return Manifest{}, 0, errBadMagic
	}
	if !bytes.Equal(magicBuf[0:4], magicText[:]) {
		return Manifest{}, 0, errBadMagic
	}

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Verify the directory actually contains a Badger database (a MANIFEST file) and that the path passed to badger.Open is correct
  2. Restore the MANIFEST from a backup snapshot if one exists
  3. 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
  4. If data is expendable, delete the whole database directory and let Badger create a fresh one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at manifest.go:344 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/46710e8f3b729b05. Report an issue: GitHub.