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

[Feature Request] Warn on single line rescues with an exception value #242

Open
caspiano opened this issue Sep 9, 2021 · 0 comments
Open

Comments

@caspiano
Copy link
Contributor

caspiano commented Sep 9, 2021

Single-line rescue expressions swallow all exceptions, returning the argument to the rescue.

It's a relatively common mistake to put an exception as the argument, mistakingly assuming that it will rescue from that exception alone, rather than all exceptions.

See the example below.

class SpecificError < Exception
end

class OtherError < Exception
end

def raises_other_error
  raise OtherError.new
end

result = raises_other_error rescue SpecificError

puts result # => SpecificError

I propose that ameba produces a warning when the argument to a single-line rescue is an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants