You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is there a typo in the Suppressing Exceptions section? #887
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.
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!
Add one more to the disagree pile. inline rescue nil is a code smell and big no-no as it does in fact mask exceptions you haven't even considered yet. What about instead of #good or #bad , something like #questionable or #only_ok_in_some_cases
This is what I meant above with “fair use”.
A better explanation will be:
# ok’ish - I fully acknowledge what exception was suppressed
File.delete(config_file_name) rescue nil # NOTE: we don’t care if the file is missing, or we lack permissions, or it’s a directiry. We just swallow the exception, as there is no point to recover.
If you agree, a PR is welcome.
As it was pointed out in prior changes, returning nil can be deliberate choice.
But we only can consider it “returning” at the end of a method/block.
Otherwise, this is pure suppression, and should conscious and deliberate for a good reason.
Activity
pirj commentedon Oct 6, 2021
It indeed looks confusing.
It was originally introduced as a bad example, see 4240682#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R961
This is how bad turned good 3a20519
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:
juanpaco commentedon Oct 6, 2021
I'm definitely happy to help the project--- I'm struggling with my orthodoxy of not seeing
rescue nilas 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!
gpopescu commentedon Jan 9, 2025
Add one more to the disagree pile. inline
rescue nilis a code smell and big no-no as it does in fact mask exceptions you haven't even considered yet. What about instead of #good or #bad , something like #questionable or #only_ok_in_some_casespirj commentedon Jan 9, 2025
This is what I meant above with “fair use”.
A better explanation will be:
If you agree, a PR is welcome.
As it was pointed out in prior changes, returning nil can be deliberate choice.
But we only can consider it “returning” at the end of a method/block.
Otherwise, this is pure suppression, and should conscious and deliberate for a good reason.