{"record":{"id":"4abaa543d8fc0263","repo":"dgraph-io/badger","slug":"invalid-range-s","errorCode":null,"errorMessage":"Invalid range: %s","messagePattern":"Invalid range: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"trie/trie.go","lineNumber":57,"sourceCode":"// NewTrie returns Trie.\nfunc NewTrie() *Trie {\n\treturn &Trie{\n\t\troot: newNode(),\n\t}\n}\n\n// parseIgnoreBytes would parse the ignore string, and convert it into a list of bools, where\n// bool[idx] = true implies that key[idx] can be ignored during comparison.\nfunc parseIgnoreBytes(ig string) ([]bool, error) {\n\tvar out []bool\n\tif ig == \"\" {\n\t\treturn out, nil\n\t}\n\n\tfor _, each := range strings.Split(strings.TrimSpace(ig), \",\") {\n\t\tr := strings.Split(strings.TrimSpace(each), \"-\")\n\t\tif len(r) == 0 || len(r) > 2 {\n\t\t\treturn out, fmt.Errorf(\"Invalid range: %s\", each)\n\t\t}\n\t\tstart, end := -1, -1 //nolint:ineffassign\n\t\tif len(r) == 2 {\n\t\t\tidx, err := strconv.Atoi(strings.TrimSpace(r[1]))\n\t\t\tif err != nil {\n\t\t\t\treturn out, err\n\t\t\t}\n\t\t\tend = idx\n\t\t}\n\t\t{\n\t\t\t// Always consider r[0]\n\t\t\tidx, err := strconv.Atoi(strings.TrimSpace(r[0]))\n\t\t\tif err != nil {\n\t\t\t\treturn out, err\n\t\t\t}\n\t\t\tstart = idx\n\t\t}\n\t\tif start == -1 {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/trie/trie.go#L39-L75","documentation":"parseIgnoreBytes parses the IgnoreBytes field of a pb.Match (a comma-separated list of byte indices, optionally with dash ranges, e.g. \"3, 5-8\") into a boolean mask. This error is returned when a comma-separated element splits into more than two dash-separated parts (e.g. \"1-2-3\") or an empty element produces zero parts, so it cannot be interpreted as a single index or a start-end range.","triggerScenarios":"Calling Trie.AddMatch (or DeleteMatch, which both go through fix) with m.IgnoreBytes containing an element with two or more dashes such as \"0-1-2\", or an element like \",,\" that trims to an empty string yielding zero split parts.","commonSituations":"Hand-written IgnoreBytes strings with typos, programmatically generated range strings that were formatted with more than one dash, or concatenating ranges with dashes instead of commas. Note: an element like \"abc\" (non-numeric) does NOT hit this line; it fails later at strconv.Atoi.","solutions":["Fix the IgnoreBytes string so each comma-separated element is either a single index (\"3\") or exactly one dash range (\"5-8\").","Replace multiple dashes in a range spec with commas for individual indices, e.g. \"1-2-3\" becomes \"1-2,3\" or \"1,2,3\".","Trim stray separators: build the string with strings.Join(indices, \",\") instead of manual concatenation to avoid empty or malformed elements.","Validate the format with a regex like ^\\d+(-\\d+)?$ per element before calling AddMatch."],"exampleFix":"// before\nm := pb.Match{Prefix: []byte(\"aaaa\"), IgnoreBytes: \"0-1-2\"}\ntrie.AddMatch(m, 1) // Invalid range: 0-1-2\n// after\nm := pb.Match{Prefix: []byte(\"aaaa\"), IgnoreBytes: \"0-1,2\"}\ntrie.AddMatch(m, 1)","handlingStrategy":"validation","validationCode":"func validIgnoreBytes(ig string) bool {\n\tif ig == \"\" { return true }\n\tfor _, each := range strings.Split(ig, \",\") {\n\t\tparts := strings.Split(strings.TrimSpace(each), \"-\")\n\t\tif len(parts) < 1 || len(parts) > 2 { return false }\n\t}\n\treturn true\n}\n// if !validIgnoreBytes(m.IgnoreBytes) { /* reject before AddMatch */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build IgnoreBytes with strings.Join instead of manual concatenation","Never use more than one dash per element","Unit-test the ignore spec format at config load time"],"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"}