Skip to content

fix(parser): report syntax errors at their real position - #190

Merged
prrao87 merged 1 commit into
mainfrom
fix/cypher-syntax-error-positions
Nov 21, 2026
Merged

prrao87 merged 1 commit into
mainfrom
fix/cypher-syntax-error-positions

Conversation

@prrao87

@prrao87 prrao87 commented Nov 21, 2026

Copy link
Copy Markdown
Member

Why

Every Cypher syntax error was reported at position 0, with nom's internal debug output as the message. nom's alt, opt and many0 backtrack and throw away the inner errors, so the error that reached the top almost always pointed at the start of the query and said nothing about what was wrong.

Fixes #184.

What changed

Before:

Cypher parse error at position 0: Failed to parse Cypher query: Parsing Error: Error { input: "MATCH (n:Person RETURN n", code: Tag }

After:

Cypher syntax error at line 1, column 17: expected '{' or ')', found 'RETURN'
  • The parser now records the furthest point any parser reached before failing, and the tokens it tried there. The tag, tag_no_case and char parsers are wrapped to record what they expected, and a failed name reads as "a name". The error reports that point as a line and column, the expected tokens, and what it found instead.
  • Errors that stop parsing outright now carry their own message and position: a negative SKIP/LIMIT, an out-of-range integer or float literal, and DISTINCT on a non-aggregate function.
  • GraphError::ParseError gains line and column fields. position is now the real byte offset. The display text changes from "Cypher parse error at position N" to "Cypher syntax error at line L, column C". Nothing in the repository matched on the old text.
  • Write clauses still raise UnsupportedFeature first, as added in fix(parser): reject write clauses as unsupported features #189.
  • The Rust errors table in the docs describes the new message.

Known limit: the furthest failure is a heuristic. Because keywords are accepted as variable names, WHERE n.age > followed by RETURN n parses RETURN as the right-hand side and reports the error at the n after it.

Validation

  • cargo test --workspace: all suites pass, including a new parser test covering the cases above.
  • cargo clippy --workspace --all-targets -- -D warnings: clean.
  • zensical build --strict and typos@1.52.0: clean.
  • Python and Node.js tests weren't run locally. The bindings only pass the error's display text through, and no test there matches on it. CI covers both.

🤖 Generated with Claude Code

Parse errors always said position 0 and showed nom's debug output,
because alt/opt/many0 backtrack and drop the inner errors. Record the
furthest point any parser reached and what it expected there, and
report line, column, the expected tokens and what was found.

Fixes #184
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Deploying lance-csr with  Cloudflare Pages  Cloudflare Pages

Latest commit: 32ad157
Status: ✅  Deploy successful!
Preview URL: https://e047051a.lance-csr.pages.dev
Branch Preview URL: https://fix-cypher-syntax-error-posi.lance-csr.pages.dev

View logs

@prrao87
prrao87 marked this pull request as ready for review November 21, 2026 21:15
@prrao87
prrao87 merged commit fa82e49 into main Nov 21, 2026
10 checks passed
@prrao87
prrao87 deleted the fix/cypher-syntax-error-positions branch November 21, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report Cypher syntax errors at their real position with a readable message

1 participant