{"record":{"id":"3c9c26ffcd27a35c","repo":"wavetermdev/waveterm","slug":"invalid-index-at-position-d-v","errorCode":null,"errorMessage":"invalid index at position %d: %v","messagePattern":"invalid index at position (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/ijson/ijson.go","lineNumber":74,"sourceCode":"\t\t\"data\": value,\n\t}\n}\n\nvar pathPartKeyRe = regexp.MustCompile(`^[a-zA-Z0-9:_#-]+`)\n\nfunc ParseSimplePath(input string) ([]any, error) {\n\tvar path []any\n\t// Scan the input string character by character\n\tfor i := 0; i < len(input); {\n\t\tif input[i] == '[' {\n\t\t\t// Handle the index\n\t\t\tend := strings.Index(input[i:], \"]\")\n\t\t\tif end == -1 {\n\t\t\t\treturn nil, fmt.Errorf(\"unmatched bracket at position %d\", i)\n\t\t\t}\n\t\t\tindex, err := strconv.Atoi(input[i+1 : i+end])\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid index at position %d: %v\", i, err)\n\t\t\t}\n\t\t\tpath = append(path, index)\n\t\t\ti += end + 1\n\t\t} else {\n\t\t\t// Handle the key\n\t\t\tj := i\n\t\t\tfor j < len(input) && input[j] != '.' && input[j] != '[' {\n\t\t\t\tj++\n\t\t\t}\n\t\t\tkey := input[i:j]\n\t\t\tif !pathPartKeyRe.MatchString(key) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid key at position %d: %s\", i, key)\n\t\t\t}\n\t\t\tpath = append(path, key)\n\t\t\ti = j\n\t\t}\n\t\tif i < len(input) && input[i] == '.' {\n\t\t\ti++","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/ijson/ijson.go#L56-L92","documentation":"Inside bracket syntax, ParseSimplePath requires the contents between '[' and ']' to parse as an integer via strconv.Atoi. If it does not (e.g. 'abc', '', '1.5'), it returns 'invalid index at position %d' with the underlying Atoi error. Array indices in ijson paths must be plain non-negative integers.","triggerScenarios":"Calling ParseSimplePath with bracket contents that are not integers: \"items[first]\", \"a[]\", \"list[01x]\", or a negative-looking/fractional index.","commonSituations":"Users writing named keys inside brackets (JavaScript-object habit) instead of dot notation; empty brackets from templating; copy-pasting paths from JS where bracket contents were strings.","solutions":["Use dot notation for keys: \"items.name\" instead of \"items[name]\".","Ensure bracket contents are a plain integer: \"items[0]\".","Sanitize user-supplied path strings with a regex like ^\\w+(\\.\\w+|\\[\\d+\\])*$ before parsing."],"exampleFix":"// before\npath, err := ijson.ParseSimplePath(\"items[first]\") // invalid index\n// after\npath, err := ijson.ParseSimplePath(\"items.0\")        // key form, or:\n_ = path\npath2, err2 := ijson.ParseSimplePath(\"items[0]\")     // integer index form","handlingStrategy":"validation","validationCode":"var simplePathRe = regexp.MustCompile(`^[a-zA-Z0-9:_#-]+(\\.[a-zA-Z0-9:_#-]+|\\[\\d+\\])*$`)\nif !simplePathRe.MatchString(userPath) {\n    return fmt.Errorf(\"path must be key.name[0] form with integer indices\")\n}","typeGuard":null,"tryCatchPattern":"path, err := ijson.ParseSimplePath(input)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid index\") {\n        return fmt.Errorf(\"array indices must be integers, e.g. items[0]: %w\", err)\n    }\n    return err\n}","preventionTips":["Restrict UI/CLI path entry to key[0].subkey syntax and validate with a regex before parsing.","Use dot notation for string keys; reserve brackets strictly for integer indices.","Document the index grammar wherever users can type paths."],"tags":["parsing","path","validation"],"backgroundTag":"path-parse-error","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}