-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lint/ShadowedException fails for rescue nil #3249
Comments
I can update the code to safeguard against this, but when I try out an example for rescuing [2] pry(main)> begin
[2] pry(main)* 1/0
[2] pry(main)* rescue nil
[2] pry(main)* puts 'rescued'
[2] pry(main)* end
TypeError: class or module required for rescue clause |
What version of ruby are you using? Have you tried putting that code into a |
The example that I posted was run against Ruby 2.3.0. I tried it in a # test.rb
begin
1/0
rescue nil
puts 'rescued'
end
According to the output of I can update this cop to account for |
Sorry, I think I misunderstood what you meant by
To clarify, writing begin
1/0
rescue nil
puts 'rescued'
end is perfectly correct from a syntax perspective. However, it does raise a So you are probably right, it is an edge-case. We just ran into this because of a code-smell. Essentially we had something like begin
puts('This never fails')
puts('Thus we never run into the TypeError`)
rescue nil
puts('rescued')
end in our code. So we never ran into the |
Thank you for the clarification, I believe that we are on the same page now. Since this does not produce a RuboCop can check for |
The "non-inline" `rescue nil` was allowed in Ruby 1.9, but disallowed since 2.0: rubocop#3249 (comment) A bit of the code handling `rescue nil` was removed from this cop in 7ef0cf4 (rubocop#4846), but there was still a bit left behind, plus a few specs.
Test code
Actual behavior
An error occurred while Lint/ShadowedException cop was inspecting /test.rb
RuboCop version
The text was updated successfully, but these errors were encountered: