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

Lint/UselessRescue: False positive for re-raising in parent thread #11682

Closed
franzliedke opened this issue Mar 9, 2023 · 0 comments · Fixed by #11683
Closed

Lint/UselessRescue: False positive for re-raising in parent thread #11682

franzliedke opened this issue Mar 9, 2023 · 0 comments · Fixed by #11683
Labels

Comments

@franzliedke
Copy link
Contributor

We're monkey-patching a gem to elevate its exceptions to a parent thread.

  def patched_method
    super
  rescue ::Exception => ex # rubocop:disable Lint/RescueException
    Thread.current[:parent].raise(ex)
  end

Expected behavior

I believe Lint/UselessRescue should not complain about the raise method call on another thread.

Actual behavior

file/with/monkeypatch.rb:18:3: W: Lint/UselessRescue: Useless rescue detected.
  rescue ::Exception => ex # rubocop:disable Lint/RescueException ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

See snippet above.

RuboCop version

1.48.0 (using Parser 3.2.1.1, rubocop-ast 1.27.0, running on ruby 3.2.1) [x86_64-linux]
  - rubocop-capybara 2.17.1
  - rubocop-graphql 0.19.0
  - rubocop-performance 1.16.0
  - rubocop-rails 2.17.4
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.19.0
@koic koic added the bug label Mar 9, 2023
koic added a commit to koic/rubocop that referenced this issue Mar 9, 2023
Fixes rubocop#11682.

This PR fixes a false positive for `Lint/UselessRescue`
when using `Thread#raise` in `rescue` clause.
In fact, any method call with a receiver will not be "useless rescue",
not just `Thread#raise`.
bbatsov pushed a commit that referenced this issue Mar 10, 2023
Fixes #11682.

This PR fixes a false positive for `Lint/UselessRescue`
when using `Thread#raise` in `rescue` clause.
In fact, any method call with a receiver will not be "useless rescue",
not just `Thread#raise`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants