dgraph-io/badger · error

errStop

errStop

Error message

Stop iteration

What it means

errStop is a sentinel control-flow error (declared alongside the value-log header bits in value.go) used to abort an iteration early by returning it from a callback. It does not indicate failure: callers such as read_bench check for it explicitly after the walk (errors.Is) and treat it as a normal stop request — e.g. the benchmark cancels the context and returns errStop once the sample size is reached. Guard-style usage: the fault input is not data but a caller-decided termination condition.

Source

Thrown at value.go:56

	bitDelete                 byte = 1 << 0 // Set if the key has been deleted.
	bitValuePointer           byte = 1 << 1 // Set if the value is NOT stored directly next to key.
	bitDiscardEarlierVersions byte = 1 << 2 // Set if earlier versions can be discarded.
	// Set if item shouldn't be discarded via compactions (used by merge operator)
	bitMergeEntry byte = 1 << 3
	// The MSB 2 bits are for transactions.
	bitTxn    byte = 1 << 6 // Set if the entry is part of a txn.
	bitFinTxn byte = 1 << 7 // Set if the entry is to indicate end of txn in value log.

	mi int64 = 1 << 20 //nolint:unused

	// size of vlog header.
	// +----------------+------------------+
	// | keyID(8 bytes) |  baseIV(12 bytes)|
	// +----------------+------------------+
	vlogHeaderSize = 20
)

var errStop = errors.New("Stop iteration")
var errTruncate = errors.New("Do truncate")

type logEntry func(e Entry, vp valuePointer) error

type safeRead struct {
	k []byte
	v []byte

	recordOffset uint32
	lf           *logFile
}

// hashReader implements io.Reader, io.ByteReader interfaces. It also keeps track of the number
// bytes read. The hashReader writes to h (hash) what it reads from r.
type hashReader struct {
	r         io.Reader
	h         hash.Hash32
	bytesRead int // Number of bytes read.

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Treat this sentinel as a normal termination signal, not an error: after the iteration call, check errors.Is(err, errStop) and return nil/success in that branch
  2. Do not retry or log it as a failure; it is intentionally returned by your own callback to stop traversal
  3. If you control the loop, prefer a context cancellation or a boolean return over an error sentinel for early stopping
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at value.go:56 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/048f369f7ad05922. Report an issue: GitHub.