Return structured errors
nieomylnieja opened this issue · comments
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 :)
maybe it would be enough to simply export errors.syntaxError
? This way we can use errors.As
to get to the root syntax error.