Skip to content

Provide Span information in Errors #496

Open
@elkowar

Description

@elkowar

It would be very helpful if there was some way to get span information for Lua errors – especially stuff like syntax errors. This would allow users to provide much better error diagnostics when something goes wrong. Especially in case of applications that expose Lua to the user, such as when Lua is used as a configuration language, or for embedded expressions in templating logic, this could massively improve the user experience.

I am very unfamiliar with the actual API that the different Lua implementations expose internally, so this might just be impossible to achieve... But I would hope that it isn't.
We are getting a line number in the rendered error message, and from what I can see at least during runtime there seems to be some ways to get that sort of information via inspect_stack.

Having a simple error_span: Option<Range<usize>> representing offsets into the loaded lua code where the error occurred would be perfect, but even just getting the line number, or the span of the surrounding scope, or whatever is viable to implement, would already be a massive help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions