Repository navigation
Make SQL syntax errors readable and actionable (#128) - #139
Conversation
laaielichter
left a comment
There was a problem hiding this comment.
Thank you @amritkang165. #128 is yours (your claim at 20:14 on 2026-11-10 was the only one; I have assigned it), and this PR does what the issue asks, carefully.
What I checked. I merged f26440d onto current main (c48adf8) in a scratch worktree (a fast-forward), on Python 3.13 / Linux: ruff check . passes and pytest -q gives 907 passed, 10 skipped. gulliver selftest security passes all 151 corpus cases, which matters because _classify is the read-only gate and this PR changes what it parses.
Against #128's "Done when":
- The three examples now read
at line 1, column 13, near "FROM": Expected table name.,at line 1, column 12, near "c": Invalid expression / Unexpected token.andat line 1, column 12 (end of input): Could not tokenize SQL; check for an unterminated quote or comment.None has<TokenorTokenType, status staysblock, exit code stays 2. next_stepfor a syntax error is the exact text the issue suggests.DROP TABLE t,SELECT 1; SELECT 2and a data-changing CTE keep their old messages and hints.SELECT 1;and;;with whitespace still pass.- Parsing the original
sqlinstead of the stripped text is the right way to get real positions, and I could not find a case where the gate decides differently. Passingparse_erroras a flag, rather than matching the message text, is a good choice. - Tests cover all four dialects, a mid-query error, leading whitespace, unterminated quote and comment,
lint/preflight/rehearse/runexit codes and advice, and file lint (GV900). The docs, AGENTS.md, llms.txt and the skill are updated. Nothing in the diff is outside the scope.
Two small notes, neither blocks the merge:
- The CHANGELOG line is at the end of
### Added. That is fine for an enhancement and keeps it away from the other open PRs, which add to### Fixed. - Other open PRs also add tests at the end of
tests/test_cli_and_mcp.py. Whichever lands second needs agit merge origin/mainand to keep both blocks.
CI: ci and codeql for this commit are action_required (a maintainer has to approve a first-time contributor's run), so Linux, macOS and Windows have not run on GitHub yet; please do not worry, it is not a failure.
Next free one if you want it, after #129 and #128: #126 (gulliver.toml with a wrong-type section crashes with a traceback).
Generated by Claude Code
|
@amritkang165 #105 just merged, so Generated by Claude Code |
|
Merged main and kept both test blocks. All 919 tests pass, with 10 PostgreSQL tests skipped. Ruff and the security self-test pass too. Thanks! |
laaielichter
left a comment
There was a problem hiding this comment.
Thank you @amritkang165, the merge of main is clean and both test blocks are kept.
What I checked on 3b2421a. The code is line for line the same as f26440d, which I approved before; the only differences are the merge itself and the CHANGELOG line, which now sits under ## Unreleased / ### Added above ## 0.4.0, where it belongs. With current main merged in: ruff check . passes, pytest -q gives 922 passed, 10 skipped, and gulliver selftest security passes all 151 corpus cases.
One more merge of main, sorry. #147 landed today and opened ## Unreleased / ### Fixed in CHANGELOG.md at the same spot, so this PR conflicts in that file again (nothing else). Please keep both under the one ## Unreleased heading: your ### Added block and the ### Fixed list from main.
CI: ci and codeql for this head are action_required, so the 11 required checks have not run on GitHub yet; the maintainer has to approve the runs. Once main is merged in and they are green, this is ready to merge.
Generated by Claude Code
|
@amritkang165 a small heads-up: #147 and its changelog credit landed on Generated by Claude Code |
|
Good news for part of the conflict: the CHANGELOG part got easier. We changed the rule so contributors don't edit CHANGELOG.md any more; we add your entry with credit when we merge. When you merge main, just take main's version of CHANGELOG.md (or drop your change to it). The conflicts in Generated by Claude Code |
laaielichter
left a comment
There was a problem hiding this comment.
Checked the head locally: full suite 1037 passed, 10 skipped; ruff check . clean. Reproduced #128 on main (TypeError/raw token repr) and on this head the message gives the line, column and the "Expected table name" detail with exit code 2. The new tests fail on main, so they cover the change.
Thanks @amritkang165 for the clear messages and the regression tests.
Generated by Claude Code
What and why
SQL syntax errors currently expose SQLGlot’s internal token details and tell users to send a SELECT even when the problem is a typo. This formats the structured parser description, line, column and highlighted token into a readable message. Leading whitespace is preserved when parsing so positions refer to the supplied SQL.
Tokenizer failures have no structured position, so they use an explicitly labelled end-of-input fallback with a hint to check for an unterminated quote or comment. Lint, preflight, rehearse and run give syntax-specific retry advice while keeping status
blockand exit code2. Existing advice for multiple statements, non-SELECT statements and security blocks is preserved. File lint uses the same wording and keeps its GV900 severity policy.Fixes #128
How it was tested
ruff check .andgit diff --checkpass.Tested on macOS arm64 with Python 3.14.7. The three issue examples were also checked through the CLI; all return readable diagnostics and exit code 2. Hosted CI results are tracked separately on this PR.
Merged current main on 2026-11-15, preserving both branches’ CLI/MCP tests and both documentation sections. CHANGELOG.md matches main, following the updated contribution guide.