-
Notifications
You must be signed in to change notification settings - Fork 30
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
Should the caller deal with *retryableError
#5
Comments
Hey @Deleplace - thanks for opening an issue.
My thinking (and I'm open to being challenged here) is that the developer has control over whether a particular error should be "retryable" or not (which is why you have to explicitly wrap an error as retryable with Now, it does get a little confusing when you have multiple possible returned errors: retry.Do(ctx, b, func(ctx context.Context) error {
if err := thing1(); err != nil {
return err // don't retry
}
if err := thing2(); err != nil {
return retry.RetryableError(err)
}
}) In this case, I agree it's difficult for the caller to know whether it's "safe" to unwrap the error, since errors from |
Thank you Seth for this quick action, yes #6 is exactly what I was thinking. My code at call site was doing this safe but boilerplaty check:
Indeed for a moment I forgot that my own client code was explicitly doing the wrapping |
There's something weird going on with the release v0.2.0, I'll open a distinct issue for this: #7 |
This issue has been automatically locked since there has not been any |
Hello Seth, thanks for the nice facility that I'm trying to use for the first time.
It seems that:
Do
signature says it returns anerror
, which is idiomatic (instead of a more specific and error-prone error type);Do
returnsnil
;Do
ignores the results of the first failed attempts, and returns the error of the very last failed attempt, wrapped in a*retryableError
.If my understanding (the above bullets) is correct, then it seems that it would be even nicer to return the "root cause" error to the caller of
Do
, i.e. not wrapped in a*retryableError
. Shall I try a PR?Caveat: maybe I'm not familiar enough with
errors.As
andinterface {Unwrap() error}
, which means that it would be, in fact, more idiomatic to keep the*retryableError
as a visible trace of the retry device, and let the caller unwrap/test the returned error.The text was updated successfully, but these errors were encountered: