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

Some improvements around error tolerance #320

Merged
merged 3 commits into from
Nov 22, 2024
Merged

Some improvements around error tolerance #320

merged 3 commits into from
Nov 22, 2024

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Nov 22, 2024

Motivation

  1. Because neither Ruby LSP's Show syntax tree command nor websites like Ruby Playground displays Prism's error messages, I added a new task to display a file's parse tree and Prism errors. This will make it easier to work with syntax-incorrect Ruby files.

  2. Keep Prism error id's type for easy comparison

    We currently don't use the converted value and keeping the pm_diagnostic_id_t type makes it easy to compare the value with PM_ERR_* constants directly.

  3. Stop surfacing Prism's EOF error

    It usually appears when there's an unclosed statements/assignments, where the root error will also be surfaced. So it's not exactly important to surface this error.

    But more importantly, because Prism puts this error at the very last line of the file when there's a missing end, it can't be represented in Sorbet's error comments.

Test plan

See included automated tests.

We currently don't use the converted value and keeping the `pm_diagnostic_id_t`
type makes it easy to compare the value with `PM_ERR_*` constants directly.
It usually appears when there's an unclosed statements/assignments, where
the root error will also be surfaced. So it's not exactly important to
surface this error.

But more importantly, because Prism puts this error at the very last line
of the file when there's a missing `end`, it can't be represented in
Sorbet's error comments.
@st0012 st0012 requested a review from egiurleo November 22, 2024 18:44
@st0012 st0012 merged commit 5185491 into prism Nov 22, 2024
1 check passed
@st0012 st0012 deleted the error-handling-prep branch November 22, 2024 18:58

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Comment on lines +1215 to +1216
// EOF error is always pointed to the very last line of the file, which can't be expressed in Sorbet's
// error comments

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we provide an alternative error location that makes this work?

E.g. to match this behaviour: https://sorbet.run/#%23%20typed%3A%20false%0A%0A%22missing%20close%20quote

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.

3 participants