dgraph-io/badger · error

ErrInvalidDump

ErrInvalidDump

Error message

Data dump cannot be read

What it means

ErrInvalidDump is returned when a previously made data dump (from DB.Dump / stream writer output) cannot be loaded into the database via DB.Load. The dump file is missing, truncated, or corrupted so its entries cannot be replayed. Defined in errors.go as a sentinel error.

Source

Thrown at errors.go:76

	// ErrRejected is returned if a value log GC is called either while another GC is running, or
	// after DB::Close has been called.
	ErrRejected = stderrors.New("Value log GC request rejected")

	// ErrInvalidRequest is returned if the user request is invalid.
	ErrInvalidRequest = stderrors.New("Invalid request")

	// ErrManagedTxn is returned if the user tries to use an API which isn't
	// allowed due to external management of transactions, when using ManagedDB.
	ErrManagedTxn = stderrors.New(
		"Invalid API request. Not allowed to perform this action using ManagedDB")

	// ErrNamespaceMode is returned if the user tries to use an API which is allowed only when
	// NamespaceOffset is non-negative.
	ErrNamespaceMode = stderrors.New(
		"Invalid API request. Not allowed to perform this action when NamespaceMode is not set.")

	// ErrInvalidDump if a data dump made previously cannot be loaded into the database.
	ErrInvalidDump = stderrors.New("Data dump cannot be read")

	// ErrZeroBandwidth is returned if the user passes in zero bandwidth for sequence.
	ErrZeroBandwidth = stderrors.New("Bandwidth must be greater than zero")

	// ErrWindowsNotSupported is returned when opt.ReadOnly is used on Windows
	ErrWindowsNotSupported = stderrors.New("Read-only mode is not supported on Windows")

	// ErrPlan9NotSupported is returned when opt.ReadOnly is used on Plan 9
	ErrPlan9NotSupported = stderrors.New("Read-only mode is not supported on Plan 9")

	// ErrTruncateNeeded is returned when the value log gets corrupt, and requires truncation of
	// corrupt data to allow Badger to run properly.
	ErrTruncateNeeded = stderrors.New(
		"Log truncate required to run DB. This might result in data loss")

	// ErrBlockedWrites is returned if the user called DropAll. During the process of dropping all
	// data from Badger, we stop accepting new writes, by returning this error.
	ErrBlockedWrites = stderrors.New("Writes are blocked, possibly due to DropAll or Close")

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Regenerate the dump with db.Dump from a healthy DB and retry Load
  2. Verify the dump file size and integrity (checksum) before loading
  3. Ensure the producing and consuming Badger versions have compatible dump formats
  4. Use KVList version-prefixed format checks / stream writer for cross-version migration

Example fix

// before
f, _ := os.Open("backup.dump")
db.Load(f, maxPendingWrites)
// after
fi, err := os.Stat("backup.dump")
if err != nil || fi.Size() == 0 {
	return fmt.Errorf("dump missing or empty: %w", err)
}
f, _ := os.Open("backup.dump")
if err := db.Load(f, maxPendingWrites); err != nil {
	return fmt.Errorf("dump unreadable, regenerate backup: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

fi, err := os.Stat(dumpPath); if err != nil || fi.Size() == 0 { return fmt.Errorf("dump missing/empty") }

Type guard

func isInvalidDump(err error) bool { return errors.Is(err, ErrInvalidDump) }

Try / catch

if err := db.Load(dumpFile, 16); err != nil {
	if errors.Is(err, ErrInvalidDump) {
		// regenerate dump or restore from alternate backup
	}
}

Prevention

When it happens

Trigger: Calling db.Load(r) with a reader over a corrupt/incomplete dump file, or loading a dump whose format/version does not match the current Badger.

Common situations: Restoring backups across Badger versions; dumps truncated by interrupted writes or failed network transfers; piping the wrong file into Load.

Related errors


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