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

RescueWithoutErrorClass gives false positive #4740

Closed
perlun opened this issue Sep 15, 2017 · 4 comments
Closed

RescueWithoutErrorClass gives false positive #4740

perlun opened this issue Sep 15, 2017 · 4 comments
Labels
Milestone

Comments

@perlun
Copy link

perlun commented Sep 15, 2017

After upgrading to RuboCop 0.50, we are seeing RescueWithoutErrorClass being raised for code that does actually provide an error class:

lib/ecraft/sequel_library/sequel_session_store.rb:148:105: W: Lint/RescueWithoutErrorClass: Avoid rescuing without specifying an error class.

Ecraft::WebApi::SessionManager.register_store(:postgres, Ecraft::SequelLibrary::SequelSessionStore) rescue NameError # rubocop:disable RescueModifier, LineLength


Expected behavior

Rubocop should accept this code, since it provides an error class (NameError).

Actual behavior

Rubocop produced a Lint/RescueWithoutErrorClass warning.

Steps to reproduce the problem

Probably the following will do, if not, the exact example above:

puts 'hello' rescue NameError

RuboCop version

Include the output of rubocop -V. Here's an example:

Fetching rubocop 0.50.0

(don't have rubocop -V output since this was running on Travis.)

@bbatsov bbatsov added the bug label Sep 15, 2017
@bbatsov bbatsov added this to the 0.50.1 milestone Sep 15, 2017
@Drenmi
Copy link
Collaborator

Drenmi commented Sep 15, 2017

Looks like the parsed AST is different when using a rescue modifier. Working on a fix.

Drenmi added a commit to Drenmi/rubocop that referenced this issue Sep 15, 2017
…ier form `rescue`

The cop would miss cases of `rescue` without error class when used in
modifier form.

This change fixes that.
@ctm
Copy link

ctm commented Sep 17, 2017

I don't think rescue as a modifier works the way @perlun thinks it works.

irb(main):018:0> 3 / 0 rescue NameError
=> NameError

I don't know of a syntax that allows the modifier form of rescue to be restricted to a particular class. If there isn't one, then it might make sense to simply not have rubocop complain about the error class when using the modifier form.

@Drenmi
Copy link
Collaborator

Drenmi commented Sep 17, 2017

You're right @ctm. This cop should just ignore modifier form rescue. (It is handled by the RescueModifier cop.) PR incoming.

@perlun
Copy link
Author

perlun commented Sep 18, 2017

@ctm Hehe, very good point! 😆 Thanks for pointing that out. I need to fix my code...

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

No branches or pull requests

4 participants