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

Is there a typo in the Suppressing Exceptions section?

Open juanpaco opened this issue 3 years ago • 2 comments

At https://github.com/rubocop/ruby-style-guide#suppressing-exceptions, it says "Don't suppress" exceptions, but then lists do_something rescue nil as a good example.

# good
do_something rescue nil

It could be my ignorance, but that reads like an example of suppressing an exception. Am I misunderstanding? Apologies if so.

juanpaco avatar Oct 06 '21 21:10 juanpaco

It indeed looks confusing.

It was originally introduced as a bad example, see https://github.com/rubocop/ruby-style-guide/commit/4240682b0a80f0ec4a26e47c5d60cec6af51ade5#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R961

This is how bad turned good https://github.com/rubocop/ruby-style-guide/commit/3a20519560b89b568354b5f7535d67a57a9241a4

Would you like to add a brief explanation to why it's a good (fair use) example? I can suggest digging through real-world-rails/real-world-ruby-apps for inspiration.

Here's an example of how it can look like:

# good - it's apparent what's going on

pirj avatar Oct 06 '21 21:10 pirj

I'm definitely happy to help the project--- I'm struggling with my orthodoxy of not seeing rescue nil as acceptable in any case, heh. I'll need to come to terms with that. I'll browse in those examples.

I'm fine if you want to close the issue so that it doesn't add noise.

Thank you for the super fast and detailed response!

juanpaco avatar Oct 06 '21 21:10 juanpaco