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

Handle encoding error from the parser gem #289

Merged
merged 1 commit into from Apr 29, 2024

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Apr 29, 2024

This specific exception has been added only in the most recent release. Previously it threw an ArgumentError. PR in parser: whitequark/parser#999

This is not really a syntax error: Running a file with an encoding like that produces the following output:

test.rb:1: unknown encoding name: foobar (ArgumentError)

RuboCop will report it as one though, since it will pick up the error from parser_error. I don't believe it is worth it to add extra logic to make a distinction here.

@Earlopain
Copy link
Contributor Author

Errors in prism are due to the same reason that rubocop/rubocop#12822 was made.

@koic
Copy link
Member

koic commented Apr 29, 2024

Errors in prism are due to the same reason that rubocop/rubocop#12822 was made.

Temporarily resolved in #290. Can you rebase with the latest master branch?

CHANGELOG.md Outdated
@@ -2,6 +2,8 @@

## master (unreleased)

* [#289](https://github.com/rubocop/rubocop-ast/pull/289): Fix an error during parsing when encountering unknown encodings in the encoding magic comment. ([@Earlopain][])
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, sure. I looked like this one isn't done here. I added a .gitkeep file to the changelog folder to make it more clear, like in the RuboCop repo.

Copy link
Member

Choose a reason for hiding this comment

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

I added a .gitkeep file to the changelog folder to make it more clear, like in the RuboCop repo.

Can you separate the commit as they serve different purposes? It's also fine to send a separate PR.

This specific exception has been added only in the most recent release.
Previously it threw an `ArgumentError`.
@Earlopain
Copy link
Contributor Author

Temporarily resolved in #290. Can you rebase with the latest master branch?

This may be of interest to you. I openend ruby/prism#2741 to align it with the parser gem. Raising a syntax error for bare yields etc. breaks extensions like rubocop-erb that operate on code line by line. Maybe you have some thoughts on it.

Copy link
Contributor

@marcandre marcandre left a comment

Choose a reason for hiding this comment

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

Good job, thanks

@marcandre marcandre merged commit 58290df into rubocop:master Apr 29, 2024
20 checks passed
@marcandre
Copy link
Contributor

Released in 1.31.3

@Earlopain Earlopain deleted the unknown-encoding-error branch April 29, 2024 13:34
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.

None yet

3 participants