fix: don't crash when an aerial query file fails to parse - #519
Merged
Conversation
`vim.treesitter.query.get(lang, "aerial")` raises whenever the query file references node types absent from the installed grammar. Reported in stevearc#506: SQL files crash aerial with `Query error at 37:2. Invalid node type "create_policy"` because `queries/sql/aerial.scm` uses `create_policy`, which was added to tree-sitter-sql in v0.3.10 (2026-01) and is missing from older parsers (common on nvim-treesitter master branch / Neovim < 0.12). Wrap `query.get` in `pcall` and return `nil` on parse failure. Both existing callers of `get_query` already handle `nil` (init.lua:22 in `is_supported`; init.lua:184 in `get_lang_and_query`), so aerial just treats the language as treesitter-unsupported for that one user instead of crashing on every buffer enter. Emit a single warning so the user can see they need to `:TSUpdate <lang>` or switch nvim-treesitter branches; the cache stores the failure so the warning doesn't spam on every buffer. Closes stevearc#506.
stevearc
requested changes
May 24, 2026
stevearc
left a comment
Owner
There was a problem hiding this comment.
This has the look of minimally edited LLM output. Just from skimming the changes that I initially want to see are:
- remove the unnecessary, overly verbose comments
- instead of logging these errors, make them surface in the
:AerialInfodiagnostics - ensure that all tests are valuable and we're not just testing trivial logic
Contributor
Author
|
Thanks, pushed an update — errors now flow through |
Owner
|
LGTM, thanks for the PR! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #506.
vim.treesitter.query.get(lang, \"aerial\")raises whenever the query file references node types absent from the installed grammar. The current reported case: SQL files crash aerial withbecause
queries/sql/aerial.scmusescreate_policy, which was added to tree-sitter-sql in v0.3.10 (2026-01) and is missing from older parsers (very common when using nvim-treesitter master branch on Neovim < 0.12 — see DerekStride/tree-sitter-sql#347).The fix
Wrap
query.getinpcalland returnnilon parse failure insideget_query. Both existing callers already handlenil(init.lua:22inis_supported;init.lua:184inget_lang_and_query), so aerial just treats the language as treesitter-unsupported for that one user instead of crashing on every buffer enter. Emit a single user-facing warning; cache the failure so the warning doesn't spam on every buffer.This is intentionally a defensive layer only — I'm not removing
create_policyfromqueries/sql/aerial.scmsince that was added on purpose in #505 and might be used by people on newer grammars. If you'd like to additionally restructure that file (e.g. split into a stable core + extras, or dropcreate_policyto keep partial outline working on old grammars), happy to follow up in a separate PR.How this was tested
End-to-end reproduction with a synthetic queries dir that references a non-existent node type for an installed grammar (lua):
3 regression tests in `tests/helpers_spec.lua`:
All 3 pass with the fix; 2/3 fail on baseline (the success-case test passes either way).