Logging the final exception?
See original GitHub issueHello,
In order to log the final exception after all retries have failed we are currently using the fallback event:
var fallbackPolicy = builder.FallbackAsync((token, context) => { return Task.CompletedTask; }, (ex, context) => LogFinalError(ex, context));
As suggested in another thread. However since the last update this operation now longer works, we are getting an exception:
You have executed the generic .Execute<TResult> method on a non-generic FallbackPolicy. A non-generic FallbackPolicy only defines a fallback action which returns void; it can never return a substitute TResult value. To use FallbackPolicy to provide fallback TResult values you must define a generic fallback policy FallbackPolicy<TResult>. For example, define the policy as Policy<TResult>.Handle<Whatever>.Fallback<TResult>(/* some TResult value or Func<..., TResult> */);
I suppose this is linked to the fix https://github.com/App-vNext/Polly/issues/294 ?
Is there a way to attach an event on fallback without having to handle the return type?
By the way this library is great, keep on the good work!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Throwing an exception from within either
onFallback
orfallbackAction
will cause that exception to propagate further outwards; the FallbackPolicy will not swallow or govern it in any way. (Policies govern the delegate passed toExecute(...)
, or all actions of a policy deeper inside aPolicyWrap
. Policies do not guard their own actions (fallbackAction; onFallback; onRetry etc); that could lead to all manner of recursion.)FallbackPolicy
catches the exceptions it is configured to handle and passes control to the configuredfallbackAction
after callingonFallback
.FallbackPolicy
does not rethrow the exception it handled. IffallbackAction
oronFallback
rethrow it will bubble; if they do not, it will not.Hello @reisenberger , wouldn’t .Fallback with an Action prevent the Exception from actually bubbling?
Is it safe to rethrow the exception from onFallback, after logging of course?
Thank you.