-
Notifications
You must be signed in to change notification settings - Fork 297
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
Runtime Exceptions that are not in retryOn
should not be wrapped in FailsafeException
#66
Comments
+1 |
When designing this thing, I had two options for dealing with exceptions in the
I chose option 2. Why? Mostly for consistency. I felt it was more straightforward to know that any failure from a runnable/callable will be wrapped in It's somewhat of a tough call with either option. That said: I'm open to hearing arguments that option 1 would be better :) |
The current behavior (wrap everything) is particularly annoying when one wants to access the details of an exception and often results in patterns like:
with the proposed change this could be simplified to
which is much nicer to both read and write! |
@axelfontaine Good point. As an API author yourself, do you think it's confusing to say RuntimeExceptions are wrapped in FailsafeException and checked exceptions are not? |
Thanks to @axelfontaine for actually making my point properly. My main goal was to be able to distinguish between the exceptions I want to retry on from other exceptions. @jhalterman I understand the consistency argument - personally I find checked exceptions quite difficult to deal with and avoid them, so I ignored them, but I realise that sometimes you have no choice (e.g. when dealing with libraries). An alternative solution that would allow you to wrap exceptions would be to have two kind of FailsafeExceptions:
This would have the added benefit that the latter one could have the number of unsuccessful retries and potentially even a list of the errors (which is interesting if there are different errors that can occur). |
@jhalterman Not at all. Simply document clearly that runtime exception flow straight through and legacy checked exceptions are wrapped. The other nice thing about that behavior is that it makes Failsafe much less intruding. Have a method call that could fail and may need retrying? Wrap that one line with Failsafe. Done. After all you already return the return value unwrapped. Why not do the same for (runtime) exceptions? |
To elaborate on my earlier +1, as @axelfontaine said this would make Failsafe much less intrusive which is a key point. When using a library you don't want it to introduce extra boilerplates like the |
@fleipold This is a use case I've been careful to support since early on, when retries are exceeded versus when a non-retryable failure occurs. The approach I created for handling this is via listeners. Communicating different events/scenarios using event listeners felt more appropriate than encoding varied event info in return values or exceptions. See the onRetriesExceeded method in particular. Let me know if that stuff doesn't support your use case and we can talk further.
@axelfontaine This argument hits home big time since it's completely in line with how I want Failsafe to be used - simple and lightweight. I'm sold. I'll make this change and have it in the next release :) |
1.0.0 has been released with this change (should be in central shortly). |
…if an execution fails due to a checked Exception. Closes failsafe-lib#66.
I am confused by the fact that failsafe wraps RuntimeExceptions that are not specified for a retry. This leads to awkward unwrapping and checking of the type of the cause. Specifically I would expect the following test to pass:
It fails like so:
Does my expectation sound reasonable?
The text was updated successfully, but these errors were encountered: