-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow for RecoveryCallback to throw original exception #135
Comments
I guess we could change the signature if we are going to bump to a new major version. Would that solve your problem? Under what circumstances would you care? Why is |
Because this will not compile:
|
Fair enough. But it's easy to work around isn't it? I guess that's what you meant by "clunky". |
Exactly. It would require a lot of type checking and casting, etc. RecoveryCallback<T> = retryContext -> {
Throwable t = retryContext.getLastThrowable();
if (t instanceof Exception) {
throw (Exception)t;
} else if (t instanceof Throwable) {
throw new RuntimeException(t);
}
}; So basically it requires six lines instead of one, and also requires wrapping the exception in the case of |
Sure, but you would put those 6 lines in a convenience class and only use one line in practice, if this pattern was common. We can put such a convenience class in spring-retry if you like, but there are plenty already out there. Plus it’s easy to write your own. |
Granted, although that doesn't address the second issue of unnecessarily wrapping the original exception in certain cases. |
Do you have an actual use case where that matters? |
Not at the moment. My point was just that the API is slightly inconsistent here and can cause inconveniences. If you don't want to fix it there are workarounds. |
The current design of the RetryTemplate and RecoveryCallback is to not throw any exception if a recovery callback is provided. There are cases where even after recovery, the caller wants to know if the original action failed or succeeded. This can be accomplished by providing a way for the recovery callback to throw the original exception. It is currently a little clunky to do so since RecoveryCallback has a signature of
throws Exception
, whileretryContext.getLastThrowable()
provides aThrowable
, which is not compatible.The text was updated successfully, but these errors were encountered: