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

Do not use SyntaxError#path #52099

Merged
merged 1 commit into from
Jun 12, 2024
Merged

Do not use SyntaxError#path #52099

merged 1 commit into from
Jun 12, 2024

Conversation

justinko
Copy link
Contributor

@justinko justinko commented Jun 12, 2024

Fixes #52089

From what I understand, path is only set in the context of eval. When explicitly raising SyntaxError, path is nil.

Regardless of how SyntaxError is raised, the "path" always exists in SyntaxError#to_s. Therefore, we should just use #to_s.

Here is an example of the difference between path (when it's present) and to_s (the first line is path):

"(eval at /Users/jko/Developer/rails/rails/actionpack/test/dispatch/debug_exceptions_test.rb:106)"
"(eval at /Users/jko/Developer/rails/rails/actionpack/test/dispatch/debug_exceptions_test.rb:106):1: syntax error, unexpected end-of-input\nbroke_syntax =\n              ^\n"

I see no reason to use the convenience method path and it was chosen because it's simpler.

Perhaps path not being populated outside eval is a Ruby bug?

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rafaelfranca rafaelfranca merged commit ba60af6 into rails:main Jun 12, 2024
2 of 3 checks passed
rafaelfranca added a commit that referenced this pull request Jun 12, 2024
rafaelfranca added a commit that referenced this pull request Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error undefined method start_with?' for nil` when logging
2 participants