{"record":{"id":"b250a10abc06a821","repo":"dgraph-io/badger","slug":"while-parsing-ignore-bytes-s-w","errorCode":null,"errorMessage":"while parsing ignore bytes: %s: %w","messagePattern":"while parsing ignore bytes: (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"trie/trie.go","lineNumber":124,"sourceCode":"// to match the length of the Prefix passed.\n//\n// Consider a prefix = \"aaaa\". If the IgnoreBytes is set to \"0, 2\", then along with key \"aaaa...\",\n// a key \"baba...\" would also match.\nfunc (t *Trie) AddMatch(m pb.Match, id uint64) error {\n\treturn t.fix(m, id, set)\n}\n\nconst (\n\tset = iota\n\tdel\n)\n\nfunc (t *Trie) fix(m pb.Match, id uint64, op int) error {\n\tcurNode := t.root\n\n\tignore, err := parseIgnoreBytes(m.IgnoreBytes)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"while parsing ignore bytes: %s: %w\", m.IgnoreBytes, err)\n\t}\n\tfor len(ignore) < len(m.Prefix) {\n\t\tignore = append(ignore, false)\n\t}\n\tfor idx, byt := range m.Prefix {\n\t\tvar child *node\n\t\tif ignore[idx] {\n\t\t\tchild = curNode.ignore\n\t\t\tif child == nil {\n\t\t\t\tif op == del {\n\t\t\t\t\t// No valid node found for delete operation. Return immediately.\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\tchild = newNode()\n\t\t\t\tcurNode.ignore = child\n\t\t\t}\n\t\t} else {\n\t\t\tchild = curNode.children[byt]","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/trie/trie.go#L106-L142","documentation":"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).","triggerScenarios":"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).","commonSituations":"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.","solutions":["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.","Pre-validate with a regex per comma element: ^\\s*\\d+\\s*(-\\s*\\d+\\s*)?$. ","Ensure indices are plain base-10 integers without units or extra characters (\"3\", not \"3rd\" or \"0x3\").","If IgnoreBytes is empty it is legal; pass \"\" rather than whitespace-only strings with stray characters."],"exampleFix":"// before\nerr := trie.AddMatch(pb.Match{Prefix: pfx, IgnoreBytes: \"3, 5-a\"}, id)\n// while parsing ignore bytes: 3, 5-a: strconv.Atoi: parsing \"a\": invalid syntax\n// after\nerr := trie.AddMatch(pb.Match{Prefix: pfx, IgnoreBytes: \"3, 5-8\"}, id)","handlingStrategy":"try-catch","validationCode":"var ignoreElemRe = regexp.MustCompile(`^\\s*\\d+\\s*(-\\s*\\d+\\s*)?$`)\nfunc ignoreBytesValid(ig string) bool {\n\tif strings.TrimSpace(ig) == \"\" { return true }\n\tfor _, e := range strings.Split(ig, \",\") {\n\t\tif !ignoreElemRe.MatchString(e) { return false }\n\t}\n\treturn true\n}","typeGuard":null,"tryCatchPattern":"if err := trie.AddMatch(m, id); err != nil {\n\tvar inner error\n\tif errors.As(err, &inner) || true {\n\t\tlog.Printf(\"bad IgnoreBytes %q: %v\", m.IgnoreBytes, err)\n\t}\n\treturn fmt.Errorf(\"rejecting match: %w\", err)\n}","preventionTips":["Regex-validate IgnoreBytes at config ingestion time","Log the quoted IgnoreBytes from the wrapped error for fast diagnosis","Keep ignore specs machine-generated rather than free-text"],"tags":["go","badger","input-validation","trie"],"backgroundTag":"invalid-range-format","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}