-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lint/EnsureReturn cop - why ensure must not return #5949
Comments
|
Google lead me to this blog post. Apparently, |
|
I see an opportunity to improve the documentation of this cop. 😉
…On Wed, 6 Jun 2018 at 2:53, Michael Gee ***@***.***> wrote:
Google lead me to this blog post
<http://blog.leshill.org/blog/2009/11/17/ensure-with-explicit-return.html>.
Apparently, ensure with explicit return also silently rescues.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5949 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAGVyhQbOS0aCbJTRBlQNouNUIdsB08sks5t5sV_gaJpZM4Ua4Eq>
.
|
|
Care to open a PR with documentation improvement @ckornaros? 🙂 |
|
Thanks for the link @mikegee ! I didn't know that ensure with return have this strange behavior. Result:
Result:
But because of the transaction, ActiveRecord::Rollback will always be raised in my case but not in all other case without transactions. |
…order to make it clear
|
Hey guys, I'd like to help with this issue. Is there anyone currently working on it? |
|
Glad I found this thread; It's good to know more about how ensure works. We had an issue in production today because of a specific Rubocop fix that was made to our code. |
|
I have similar scenario, but I need to redirect every error/exception to the own handler. Which will log and process data. And in case of error I sending further some specific value for unification reasons as here is empty def rescue_empty_result
raise EmptyValueError.new("Empty value happened..")
rescue => error
::Log.error(error, **debug_params)
ensure
return []
endIf I will remove It this case it is even sounds as wrong. ))) |
In my code I have an ensure like that:
And rubocop show me the following warning : Lint/EnsureReturn: Do not return from an ensure block.
But if I removed the return the result will not be the same.
Exemple:
So is there a reason that ensure must not return a value ?
RuboCop version
0.54.0 (using Parser 2.5.0.5, running on ruby 2.3.1 x86_64-linux)
The text was updated successfully, but these errors were encountered: