-
Notifications
You must be signed in to change notification settings - Fork 17.3k
GrammarRegistry.loadGrammar does not catch errors from addGrammar #23041
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
- Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/
- Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
- Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
- Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
Description
While investigating winstliu/language-hclrs#4, I root-caused the issue to using a newer tree-sitter version than Atom supported. However, this was non-obvious, and the only place it was reported was in the console.
When loading grammars, loadGrammar checks to make sure that readGrammar succeeds:
Lines 552 to 553 in 3f4b251
| this.readGrammar(grammarPath, (error, grammar) => { | |
| if (error) return callback(error); |
However, there are no checks for the subsequent addGrammar call:
Lines 554 to 555 in 3f4b251
| this.addGrammar(grammar); | |
| callback(null, grammar); |
Even though addGrammar can fail when (eventually) calling TreeSitterLanguageMode.parse, which itself calls parser.setLanguage which can throw.
atom/src/tree-sitter-language-mode.js
Line 117 in 3f4b251
| parser.setLanguage(language); |
Steps to Reproduce
- Install language-hclrs@0.0.2
- Set language to HCLRS
Expected behavior:
A helpful error notificaton.
Actual behavior:
Nothing! Why isn't my syntax highlighting working?
Reproduces how often:
100%
Versions
1.58.0, Windows 11 Insider.
Additional Information
N/A
