-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[11.x] retry
func - catch "Throwable" instead of Exception
#50944
[11.x] retry
func - catch "Throwable" instead of Exception
#50944
Conversation
@@ -298,7 +298,7 @@ function retry($times, callable $callback, $sleepMilliseconds = 0, $when = null) | |||
|
|||
try { | |||
return $callback($attempts); | |||
} catch (Exception $e) { | |||
} catch (Throwable $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change, so needs to target 12.x
. Before doing anything, wait for Taylor's review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, good to know 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@taylorotwell please have a look and let us know if this should be targeted to master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sethsandaru , why not this?
catch (Exception|Throwable $e) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devajmeireles it's unnecessary to do so, Exception
implements Throwable
and using union, it still introduces breaking changes
@sethsandaru what is the reason to retry errors? Errors happen on programming mistakes. For example, if there is TypeError, you should just interrupt all execution and go fix a code. |
@taylorotwell @driesvints are you sure this is a good idea? Error types are not meant to be retried. It's a sign of a persistent issue in the code, not runtime issues which may fail eventually. For example, I will pass the string to the method where the param must be an integer. If we will retry this call 10 times, this code will fail 10 times. And as @nunomaduro mentioned earlier, this is a breaking change. |
@antonkomarev from my projects, I want to retry at least 1 regardless of Errors/Exceptions (libraries, low-level, etc). We'd never know when Error/Exception happens and there would be "Error" on runtime (3rd-party stuff, WS calls, internal, etc) This change would somehow make Stuff like you mentioned "TypeError", it's already been battle-tested via unit testing & strict validation in my project. I guess other projects would follow this as well. |
@sethsandaru The queue needs to handle it to mark job as failed. Because code may be changed between jobs handling. And we could repeat execution later when code will be fixed. On the other side retry helper will never receive a modified code between tries, because all iterations are done in a single process. |
Maybe retry(3, fn () => 'foo', errorType: Throwable::class) |
Hi team,
rescue
has been catchingThrowable
for a while but not forretry
. AnError
would easily break the retry helper.This PR updates that.