{"record":{"id":"2b29fee76c7ac44e","repo":"ent/ent","slug":"unexpected-bracket","errorCode":null,"errorMessage":"unexpected bracket","messagePattern":"unexpected bracket","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dialect/sql/sqljson/sqljson.go","lineNumber":629,"sourceCode":"\t)\n\tfor i < len(dotpath) {\n\t\tswitch r := dotpath[i]; {\n\t\tcase r == '\"':\n\t\t\tif i == len(dotpath)-1 {\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected quote\")\n\t\t\t}\n\t\t\tidx := strings.IndexRune(dotpath[i+1:], '\"')\n\t\t\tif idx == -1 || idx == 0 {\n\t\t\t\treturn nil, fmt.Errorf(\"unbalanced quote\")\n\t\t\t}\n\t\t\ti += idx + 2\n\t\tcase r == '[':\n\t\t\tif p != i {\n\t\t\t\tpath = append(path, dotpath[p:i])\n\t\t\t}\n\t\t\tp = i\n\t\t\tif i == len(dotpath)-1 {\n\t\t\t\treturn nil, fmt.Errorf(\"unexpected bracket\")\n\t\t\t}\n\t\t\tidx := strings.IndexRune(dotpath[i:], ']')\n\t\t\tif idx == -1 || idx == 1 {\n\t\t\t\treturn nil, fmt.Errorf(\"unbalanced bracket\")\n\t\t\t}\n\t\t\tif !isNumber(dotpath[i+1 : i+idx]) {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid index %q\", dotpath[i:i+idx+1])\n\t\t\t}\n\t\t\ti += idx + 1\n\t\tcase r == '.' || r == ']':\n\t\t\tif p != i {\n\t\t\t\tpath = append(path, dotpath[p:i])\n\t\t\t}\n\t\t\ti++\n\t\t\tp = i\n\t\tdefault:\n\t\t\ti++\n\t\t}","sourceCodeStart":611,"sourceCodeEnd":647,"githubUrl":"https://github.com/ent/ent/blob/69d5d4deb19599f129166634e09d33addcf3f2cc/dialect/sql/sqljson/sqljson.go#L611-L647","documentation":"sqljson.ParsePath treats `[` as the start of an array-index segment. This error is returned when the `[` is the last character of the path, so no index or closing bracket can follow. It signals a truncated path expression.","triggerScenarios":"Calling ParsePath/DotPath with a path ending in `[`, e.g. `a[`, or a path like `items[0][` built by incomplete loop logic.","commonSituations":"Dynamically built paths where the index part was never appended; copy-paste truncation of long paths; template rendering that dropped the index.","solutions":["Append the numeric index and closing bracket: `a[0]`","Remove the stray `[` if indexing was not intended","Ensure index loops append `[i]` pairs together"],"exampleFix":"// before\nsqljson.Path(`items[`)\n// after\nsqljson.Path(`items[0]`)","handlingStrategy":"validation","validationCode":"if strings.HasSuffix(p, \"[\") {\n    return errors.New(\"truncated bracket segment\")\n}","typeGuard":null,"tryCatchPattern":"path, err := sqljson.ParsePath(p)\nif err != nil {\n    return fmt.Errorf(\"invalid json path %q: %w\", p, err)\n}","preventionTips":["Always append bracket and index together as fmt.Sprintf(\"[%d]\", i)","Check paths for trailing brackets before use","Unit-test dynamic path builders with the last-index case"],"tags":["go","json","path-parsing","ent"],"backgroundTag":"json-path-syntax-error","analyzedSha":"69d5d4deb19599f129166634e09d33addcf3f2cc","analyzedAt":"2026-09-03T16:51:39.799Z","contentChangedAt":"2026-09-03T16:51:39.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}