ruby-style-guide icon indicating copy to clipboard operation
ruby-style-guide copied to clipboard

style guide doesn't follow Style/RescueStandardError

Open Fryguy opened this issue 7 years ago • 2 comments

This issue has 2 parts

  1. Style/RescueStandardError isn't represented at all in the style guide
  2. In particular, https://github.com/bbatsov/ruby-style-guide/tree/2c0b4713794ea07a70ca4e1dee81405350fa7544#no-blind-rescues shows that rescue => e is "good", but this line would fail against Style/RescueStandardError 's default of "explicit".

Since this cop has 2 choices (implicit and explicit), I'm not sure how to make a PR for this change to show that it's "bad" with defaults, but "good" with changes (not even sure the guide cares about those choices)

Fryguy avatar May 29 '18 22:05 Fryguy

What about just adding a comment to the code:

# good, if Style/RescueStandardError is set to "implicit"
begin
  # a blind rescue rescues from StandardError, not Exception as many
  # programmers assume.
rescue => e
  # exception handling
end

That section of the README was primarily written with regard to rescue Exception, so I think there is certainly some value in highlighting why rescue => e is typically OK - and does not violate the above.

tom-lord avatar Jul 09 '18 15:07 tom-lord

Style/RescueStandardError isn't represented at all in the style guide

I guess we'll have to change that and add a rule about it here. :-)

good, if Style/RescueStandardError is set to "implicit"

I've avoided adding any references to specific cops in the guide, as I want it to be focused on the code itself, not on the tools.

bbatsov avatar Jun 12 '19 06:06 bbatsov