question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logging the final exception?

See original GitHub issue

Hello,

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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
reisenbergercommented, Sep 19, 2018

Is it safe to rethrow the exception from onFallback, after logging of course?

Throwing an exception from within either onFallback or fallbackAction will cause that exception to propagate further outwards; the FallbackPolicy will not swallow or govern it in any way. (Policies govern the delegate passed to Execute(...), or all actions of a policy deeper inside a PolicyWrap. Policies do not guard their own actions (fallbackAction; onFallback; onRetry etc); that could lead to all manner of recursion.)

wouldn’t .Fallback with an Action prevent the Exception from actually bubbling?

FallbackPolicy catches the exceptions it is configured to handle and passes control to the configured fallbackAction after calling onFallback. FallbackPolicy does not rethrow the exception it handled. If fallbackAction or onFallback rethrow it will bubble; if they do not, it will not.

0reactions
thurfircommented, Sep 19, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging Exceptions in Java - Loggly
A look at common approaches to exception handling and logging in Java. ... When to Log Java Exceptions ... final static Logger logger...
Read more >
How to log exceptions in Java?
Most code I've seen logs an exception by using either getMessage() or toString() . But these methods don't always capture all the information ......
Read more >
How to Log Exception Properly
By logging the developer message together with the whole exception object, we can see the developer message is printed first, followed by the ......
Read more >
Java Exceptions and How to Log Them Securely | Scalyr
It's not enough to log java exceptions: you need to log them securely. In this post, we'll teach you why and how to...
Read more >
How to Log an Exception
Canonically, the way you log an exception in SLF4J is to log a domain specific message, and include the exception as the last...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found