spring-retry icon indicating copy to clipboard operation
spring-retry copied to clipboard

Add "exposeOriginalException" option on @Retryable

Open getupdown opened this issue 6 years ago • 6 comments

Because of issue #82, I add an option on @Retryable . It decides that if original exception ( the cause wrapped in ExhaustedRetryException ) will be thrown if ExhaustedRetryException is triggered. Please review, thanks !

getupdown avatar Nov 06 '18 17:11 getupdown

@getupdown Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-issuemaster avatar Nov 06 '18 17:11 pivotal-issuemaster

@getupdown Thank you for signing the Contributor License Agreement!

pivotal-issuemaster avatar Nov 06 '18 17:11 pivotal-issuemaster

Thanks for that, and for the tests. I was wondering if it might be better implemented a layer below the interceptors, so that someone using RetryTemplate directly could benefit. The @Retryable annotation might have to pick up an attribute still, or we could think about a new annotation, but let's leave that discussion for now. Do you think maybe we could add an attribute to the RetryContext that the RetryTemplate would recognize and unwrap the exception before throwing?

dsyer avatar Nov 07 '18 08:11 dsyer

@dsyer Thanks for your replying ! I've thought about your approach carefully. I found that, if exposeOriginalException is added into RetryContext, it means , RetryPolicy must be modified . According to the method doExecute, context is generated from retryPolicy and state. I don't think it's reasonable that the relative information should be maintained inRetryPolicy.

So, how about setting a boolean value directly named exposeOriginalException as a field of RetryTemplate ?

I think, the option is only for the specific implementation of RetryOperation, namely RetryTemplate.

getupdown avatar Nov 07 '18 13:11 getupdown

Sorry for the delay. It's a tough decision. RetryTemplate tends to be global, but the decision to rethrow the original exception might be local. So on balance I guess you are right in the first place and we should simply support this feature in the annotation, at least to start with. Maybe I'll ask @garyrussell for an opinion before merging.

dsyer avatar Mar 06 '19 08:03 dsyer

From #82 @dsyer said

It's not really a @CircuitBreaker feature is it (the RetryTemplate always wraps the last failed exception)?

Actually, the RetryTemplate has a boolean throwLastExceptionOnExhausted (false by default).

So, maybe we should add a (default?) setter on RetryOperations and set throwLastExceptionOnExhausted to true if the annotation has this property set; then you wouldn't need to unwrap the ExhaustedRetryException (because it wouldn't be wrapped in the first place).

garyrussell avatar Mar 06 '19 20:03 garyrussell

Superseded by the https://github.com/spring-projects/spring-retry/commit/d3698b8cf490a6c81e8a2996c451ac7961ecb53e.

Thank you for contribution any way; looking forward for more!

artembilan avatar May 10 '24 19:05 artembilan