dgraph-io/badger · error

while parsing ignore bytes: %s: %w

Error message

while parsing ignore bytes: %s: %w

What it means

Trie.fix wraps any error from parseIgnoreBytes with the original IgnoreBytes string for context. Users see this when calling AddMatch or DeleteMatch with a malformed IgnoreBytes spec (bad separators, non-numeric indices).

Source

Thrown at trie/trie.go:124

// to match the length of the Prefix passed.
//
// Consider a prefix = "aaaa". If the IgnoreBytes is set to "0, 2", then along with key "aaaa...",
// a key "baba..." would also match.
func (t *Trie) AddMatch(m pb.Match, id uint64) error {
	return t.fix(m, id, set)
}

const (
	set = iota
	del
)

func (t *Trie) fix(m pb.Match, id uint64, op int) error {
	curNode := t.root

	ignore, err := parseIgnoreBytes(m.IgnoreBytes)
	if err != nil {
		return fmt.Errorf("while parsing ignore bytes: %s: %w", m.IgnoreBytes, err)
	}
	for len(ignore) < len(m.Prefix) {
		ignore = append(ignore, false)
	}
	for idx, byt := range m.Prefix {
		var child *node
		if ignore[idx] {
			child = curNode.ignore
			if child == nil {
				if op == del {
					// No valid node found for delete operation. Return immediately.
					return nil
				}
				child = newNode()
				curNode.ignore = child
			}
		} else {
			child = curNode.children[byt]

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Read the wrapped inner error and the quoted IgnoreBytes value to find the offending element, then correct that element to "idx" or "start-end" form.
  2. Pre-validate with a regex per comma element: ^\s*\d+\s*(-\s*\d+\s*)?$.
  3. Ensure indices are plain base-10 integers without units or extra characters ("3", not "3rd" or "0x3").
  4. If IgnoreBytes is empty it is legal; pass "" rather than whitespace-only strings with stray characters.

Example fix

// before
err := trie.AddMatch(pb.Match{Prefix: pfx, IgnoreBytes: "3, 5-a"}, id)
// while parsing ignore bytes: 3, 5-a: strconv.Atoi: parsing "a": invalid syntax
// after
err := trie.AddMatch(pb.Match{Prefix: pfx, IgnoreBytes: "3, 5-8"}, id)
Defensive patterns

Strategy: try-catch

Validate before calling

var ignoreElemRe = regexp.MustCompile(`^\s*\d+\s*(-\s*\d+\s*)?$`)
func ignoreBytesValid(ig string) bool {
	if strings.TrimSpace(ig) == "" { return true }
	for _, e := range strings.Split(ig, ",") {
		if !ignoreElemRe.MatchString(e) { return false }
	}
	return true
}

Try / catch

if err := trie.AddMatch(m, id); err != nil {
	var inner error
	if errors.As(err, &inner) || true {
		log.Printf("bad IgnoreBytes %q: %v", m.IgnoreBytes, err)
	}
	return fmt.Errorf("rejecting match: %w", err)
}

Prevention

When it happens

Trigger: Trie.AddMatch(m, id) or Trie.DeleteMatch(m, id) where m.IgnoreBytes is non-empty and fails parsing: an element with >1 dash (error 130), an empty start part (error 131), or a non-integer index such as "a,3" (strconv error).

Common situations: Deserializing match configs from YAML/JSON where IgnoreBytes was free-form text, user-supplied query patterns with typos, or passing an IgnoreBytes intended for a different key layout.

Related errors


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