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

DIscourage rescue error message checking #951

Open
simulk opened this issue Oct 17, 2024 · 1 comment
Open

DIscourage rescue error message checking #951

simulk opened this issue Oct 17, 2024 · 1 comment

Comments

@simulk
Copy link

simulk commented Oct 17, 2024

I proposed PR rubocop/rubocop#13352 to add a new Lint/NoRescueErrorMessageChecking cop that discourages rescue error matching. We built a custom cop at my company and thought it might be useful to roll it out as built in cop.

I was suggested by @dvandersluis to reach out to the community for feedback whether its a useful cop or not.

# bad
begin
  something
rescue => e
  if e.message.match?(/Duplicate entry/)
    handle_error
  end
end

# bad
begin
  something
rescue => e
  unless e.message.match?(/Duplicate entry/)
    handle_error
  end
end

# good
begin
  something
rescue ActiveRecord::RecordNotUnique => e
  handle_error
end
@pirj
Copy link
Member

pirj commented Oct 17, 2024

As a cop - yes.

As a guideline - too rare and I’d say not worth adding.

If you’re courageous enough, harvest real-world-ruby-apps and real-world-rails repos for usage examples.

I’m more inclined to close.

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

No branches or pull requests

2 participants