Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print full error chain when failing to load grammar #12744

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

NiklasJonsson
Copy link
Contributor

As per the documentation in anyhow: https://docs.rs/anyhow/latest/anyhow/struct.Error.html#display-representations to print the full error, one should use {:#}.

This helped me debug an error where a .so file would fail to load for a treesitter grammar by giving more information on the error so I'd figured I'd open a PR so that it might help others.

I didn't write a test because I'm not very familiar with the helix code and test structure but if you'd like one, please give some suggestion on how to implement it and I will 😄

@drybalka
Copy link
Contributor

drybalka commented Feb 2, 2025

I don't think a test is needed, as your PR only changes the error display. It would be helpful, however, if you could provide a recipe for testing it manually, so that I can compare the errors. In other words, what do I need to do to break the treesitter grammar loading and get an error from this part of code?

@NiklasJonsson
Copy link
Contributor Author

NiklasJonsson commented Feb 4, 2025

Sure, here is an example:

  1. Create a cpp file main.cpp
    int main() {
      return 1;
    }
  2. Open it and verify that the syntax highlighting works.
  3. Rename the cpp grammar file. mv <helix-runtime-dir>/grammars/cpp.dll <helix-runtime-dir>/grammars/cpp2.dll (I'm on windows right now, should be .so on linux)
  4. Open main.cpp again. Syntax highlighting should not work.
  5. Check the logs with :log-open
    helix_core::syntax [ERROR] Failed to load tree-sitter parser for language "cpp": Error opening dynamic library "<helix-runtime-dir>\\grammars\\cpp.dll"
    

But with my change, the logs contain

helix_core::syntax [ERROR] Failed to load tree-sitter parser for language "cpp": Error opening dynamic library "<helix-runtime-dir>\\grammars\\cpp.dll": LoadLibraryExW failed: The specified module could not be found. (os error 126)

The real issue that prompted this PR was that I had built the cpp.so against one libc but at runtime it tried to link against a much older one and got missing symbol errors. I don't have the logs for this though but the above should show the improvement.

@the-mikedavis the-mikedavis merged commit 1258111 into helix-editor:master Feb 4, 2025
6 checks passed
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.

3 participants