Skip to content

Conversation

@viralpraxis
Copy link

@viralpraxis viralpraxis commented Oct 26, 2025

ref: rubocop/rubocop-rails#1547

https://api.rubyonrails.org/classes/Kernel.html#method-i-suppress

Using Kernel.suppress(Exception) { ?? } is effectively equivalent to:

begin
  ??
rescue Exception
end

Since rescuing Exception directly is discouraged by Lint/RescueException, it makes sense to discourage this usage as well.

ref: rubocop/rubocop-rails#1547

Using `Kernel.suppress(Exception) { ?? }` is effectively equivalent to:

```ruby
begin
  ??
rescue Exception
end
```

Since rescuing `Exception` directly is discouraged by `Lint/RescueException`,
it makes sense to discourage this usage as well.

See https://rubystyle.guide/#no-blind-rescues
@viralpraxis viralpraxis force-pushed the kernel-suppress-exception branch from 5267c97 to 438bbf5 Compare October 26, 2025 11:53
@koic
Copy link
Member

koic commented Oct 27, 2025

One concern is that https://rubystyle.guide/#no-blind-rescues is a rule intended to prevent catching exceptions with incorrect handling. On the other hand, suppress is a method intended to suppress exception handling.
In other words, the goals are different, so I'm not fully convinced that suppress(Exception) should truly be treated as a bad case.

@viralpraxis
Copy link
Author

Are there any legitimate uses of suppress(Exception) in the context of Rails? I can’t think of any.

On the other hand, its easy to use Exception instead of StandardError out of inexperience just as with the "regular rescue" syntax.

Anyway, I don't insist of making this a rule, but I think a cop would be beneficial

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants