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

Return structured errors #423

Open
nieomylnieja opened this issue Feb 1, 2024 · 1 comment
Open

Return structured errors #423

nieomylnieja opened this issue Feb 1, 2024 · 1 comment

Comments

@nieomylnieja
Copy link

Is your feature request related to a problem? Please describe.
I want to be able to access the line and character reported by a parser error.
It would be also nice if the error had the ast.Node that caused it attached.

Describe the solution you'd like
Instead of returning a formatted string based error return a structured error implementing error interface.
This way we're not introducing any backwards incompatible changes but allow accessing the details reported by the error.

Describe alternatives you've considered
Currently I'm using regex to extract these details and also I've got some custom code written which helps me find the ast.Node at a given position in file (using ast.Walk).

Additional context
I'm writing an LSP for YAML, reporting diagnostics based off of this library parsing errors is crucial.

I'd be more than willing to submit a PR for that, just let me know If you're open to such change :)

@nieomylnieja
Copy link
Author

maybe it would be enough to simply export errors.syntaxError? This way we can use errors.As to get to the root syntax error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant