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

Use Result to pack the return value #11

Open
h4kuy4 opened this issue Jan 21, 2023 · 4 comments
Open

Use Result to pack the return value #11

h4kuy4 opened this issue Jan 21, 2023 · 4 comments

Comments

@h4kuy4
Copy link

h4kuy4 commented Jan 21, 2023

While I'm trying to write a plugin to highlight the code with tree sitter, I found that I can't pass the error to the outside.
I suggest that use Resut to pack the return value instead of use return value directly.

@h4kuy4 h4kuy4 changed the title Add error handle with Result Use Result to pack the return value Jan 21, 2023
@rlidwka
Copy link
Collaborator

rlidwka commented Jan 24, 2023

What errors do you expect to have? And how do you want to handle them outside?

The current assumption is that the parser should work on any user input, and that plugins should handle their own errors. If some errors can be handled better from outside, we should probably add methods like try_parse and try_render alongside of parse and render.

@h4kuy4
Copy link
Author

h4kuy4 commented Jan 27, 2023

Like highlight with treesitter, we may use tree-sitter-loader to load parser of tree sitter at runtime(we need cloned the parser's repositories previously and it is every single repository for each language).
and it is also load parser with a string called scope not just the name of language, in my test code, I use a match to handle this like image below. But if make it as a plugin an public it, I have to add all of the pairs into the match.
image
So it may happen that parsers for some languages not found. I think this type of error may need to pass to the outside, and them we can decide to print a log and ignore the error or panic the program.

@begleynk
Copy link

begleynk commented Jun 3, 2023

I'd could also vote for returning a Result from parse. I get that parsing Markdown cannot fail according to the spec. But the same is likely true for all the kinds of plugins people are writing. I found myself wanting to return an error to the user for some extensions I'm adding to Markdown.

I think there's ways around this (maybe walking the AST after parsing and looking for markers that an error occurred in the custom Nodes?) but just wanted to flag that I also ran into this.

@rlidwka
Copy link
Collaborator

rlidwka commented Jun 7, 2023

I found myself wanting to return an error to the user for some extensions I'm adding to Markdown.

Okay, I've added function try_parse() (which propagates errors) along with existing parse() (which doesn't).

See #19 for details.

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

No branches or pull requests

3 participants