Page MenuHomeSoftware Heritage

Better syntax errors for the search query language
Closed, MigratedEdits Locked

Description

Currently, the only error we can raise in case of syntax errors is "Invalid query", which is not helpful for users.

We should find a way to turn tree-sitter's partial ASTs into proper errors, so users know what to fix in their query.

Event Timeline

vlorentz triaged this task as Normal priority.Feb 11 2022, 2:16 PM
vlorentz created this task.
vlorentz added a subtask: Restricted Maniphest Task.

Possible invalid queries [WIP]:

Query: origin in 23
sexp: (ERROR (patternField) (choiceOp) (number))
root.type: ERROR
root.has_error: True
The root node's children are normal in this case.

Query: poke = mon
sexp: (ERROR (UNEXPECTED 'o') (rangeOp) (UNEXPECTED 'n'))
root.children: [<Node type=ERROR>, <Node type=rangeOp>, <Node type=ERROR>]
The type=ERROR nodes don't have any children. So <Node type=UNEXPECTED> doesn't exists in the AST, it's present only in the sexp

Query: origin = '24
sexp: '(query (filters (filter category: (patternFilter field: (patternField) op: (patternOp (equalOp)) value: (patternVal (string (stringContent) (MISSING "\'")))))))'

Right now, Tree-sitter just tries to repair the error so that it can give you back a syntax tree that works for the rest of the file.

https://github.com/tree-sitter/tree-sitter/issues/255

I'll update this comment with more examples very soon.

vlorentz closed subtask Restricted Maniphest Task as Resolved.Mar 3 2022, 3:04 PM
vlorentz reopened subtask Restricted Maniphest Task as Open.
vlorentz closed subtask Restricted Maniphest Task as Resolved.Apr 19 2022, 1:23 PM
gitlab-migration changed the status of subtask Restricted Maniphest Task from Resolved to Migrated.Jan 8 2023, 10:03 PM