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

SignalException cop incorrectly flags "Use fail instead of raise to signal exceptions #909

Closed
josh-h opened this issue Mar 19, 2014 · 1 comment
Labels

Comments

@josh-h
Copy link

josh-h commented Mar 19, 2014

With the following code snippet:

def test
  5/0
rescue ZeroDivisionError
  # handle error
rescue
  raise
end

The SignalException cop flags the error:

Use fail instead of raise to signal exceptions.

Since we are re-raising an exception this should be valid. Simplifying the code further by removing the first rescue stops the cop from flagging an issue. So, this only becomes a problem when two rescues are used, and one raise's the exception.

I created the following spec, but am too unfamiliar with the codebase to provide a fix at this time:

    it 'accepts raise in def with multiple rescues' do
      inspect_source(cop,
                     ['def test',
                      '  fail',
                      'rescue StandardError',
                      '  # handle error',
                      'rescue Exception',
                      '  raise',
                      'end'])
      expect(cop.offenses).to be_empty
    end
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 20, 2014

Thanks for reporting this. We'll have it fixed.

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

2 participants