Skip to content

Conversation

@giuliano-macedo
Copy link

@giuliano-macedo giuliano-macedo commented Oct 18, 2025

Currently when calling ts_parser_set_language, it can fail in these two cases:

if ( language->version > TREE_SITTER_LANGUAGE_VERSION || language->version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION ) return false;
if (ts_language_is_wasm(language)) {
  if ( !self->wasm_store || !ts_wasm_store_start(self->wasm_store, &self->lexer.data, language) ) return false;
}

So, ideally, in go, we should report those errors to the user.

I've noticed that when using the default flags of the current tree-sitter-cli and setting the language using go-tree-sitter,
this lead to a segfault down the line, I think it is better to fail early in these cases.

Also I could reimplement the logic that the C side is doing in the go side so that we have more precise errors, but I think this would lead to possible inconsitencies if the C-side changes and the go-side lags behind, so I just returned a generic error saying that it could not set the language, but it could be because of the version.

@giuliano-macedo giuliano-macedo force-pushed the set-language-errors branch 2 times, most recently from ecbb55c to 127afb7 Compare October 18, 2025 19:17
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.

1 participant