dgraph-io/badger · error

ErrZeroBandwidth

ErrZeroBandwidth

Error message

Bandwidth must be greater than zero

What it means

ErrZeroBandwidth is returned when a Sequence is created with a bandwidth of zero. Bandwidth controls how many sequence values Badger leases in advance; zero would make the sequence unusable, so GetSequence validates it (db.go:1439). Defined in errors.go.

Source

Thrown at errors.go:79

	// 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")

	// ErrNilCallback is returned when subscriber's callback is nil.
	ErrNilCallback = stderrors.New("Callback cannot be nil")

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Pass a positive bandwidth, e.g. db.GetSequence(key, 100)
  2. Validate config-supplied bandwidth > 0 with a fallback default before calling GetSequence
  3. Use bandwidth=1 only if strict per-call allocation is intended — never 0

Example fix

// before
seq, err := db.GetSequence([]byte("seq"), cfg.Bandwidth)
// after
bandwidth := cfg.Bandwidth
if bandwidth == 0 {
	bandwidth = 100
}
seq, err := db.GetSequence([]byte("seq"), bandwidth)
Defensive patterns

Strategy: validation

Validate before calling

if bandwidth <= 0 { return errors.New("bandwidth must be > 0") }

Try / catch

seq, err := db.GetSequence(key, bw)
if errors.Is(err, ErrZeroBandwidth) {
	return fmt.Errorf("config: sequence.bandwidth must be a positive integer")
}

Prevention

When it happens

Trigger: db.GetSequence(key, 0) — bandwidth == 0 at db.go:1439.

Common situations: Loading bandwidth from config where the value defaults to 0; computing bandwidth as a product that evaluates to zero; misunderstanding that bandwidth must be a positive integer.

Understand the failure class

Background: "must be a positive integer", "cannot be empty", "invalid argument": how invalid-argument errors work across open-source libraries — this error's family across 33 libraries.

Related errors


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