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

Build the ability to format errors #1796

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Build the ability to format errors #1796

merged 1 commit into from
Nov 21, 2023

Conversation

kddnewton
Copy link
Collaborator

Previously, we only supported error messages that were constant strings. This works for the most part, but there are some times where we want to include some part of the source in the error message to make it better.

For example, instead of "Token is reserved" it's better to write "_1 is reserved".

To do this, we now support allocating error messages at runtime that are built around format strings.

I don't actually think this should be the real solution here. Ideally we would provide the ability for these fields to be described so that we could template out some nice Ruby syntax error classes. But for now, this gets us closer to passing Ruby spec so I'd like to build this intermediate step.

cc @enebo this should allow us to start fixing some specific error message assertions. Now that we have this, would you be able to open an issue with the error messages that are not lining up?

@kddnewton kddnewton force-pushed the format-errors branch 2 times, most recently from e0fc7d2 to 9a3ea2c Compare November 10, 2023 07:00
@enebo
Copy link
Collaborator

enebo commented Nov 10, 2023

@kddnewton sure. I will start opening issues next week. In many cases it is not even the dynamic aspect you are fixing here but just more explicit english grammar (like adding an article in prism which was omitted in original warn/error).

Previously, we only supported error messages that were constant
strings. This works for the most part, but there are some times
where we want to include some part of the source in the error
message to make it better.

For example, instead of "Token is reserved" it's better to write
"_1 is reserved".

To do this, we now support allocating error messages at runtime
that are built around format strings.
@kddnewton kddnewton merged commit 7e6aa17 into main Nov 21, 2023
46 checks passed
@kddnewton kddnewton deleted the format-errors branch November 21, 2023 02:43
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 21, 2023
(ruby/prism#1796)

Previously, we only supported error messages that were constant
strings. This works for the most part, but there are some times
where we want to include some part of the source in the error
message to make it better.

For example, instead of "Token is reserved" it's better to write
"_1 is reserved".

To do this, we now support allocating error messages at runtime
that are built around format strings.

ruby/prism@7e6aa17deb
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.

2 participants