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.

Change default logging for unhandled exceptions

See original GitHub issue

Currently, an unhandled exception thrown in a UniTask will be logged as a warning. Normally, an unhandled exception would be logged by Unity with Debug.LogException(). This behavior can be changed by setting UniTaskScheduler.UnobservedExceptionWriteLogType:

UniTaskScheduler.UnobservedExceptionWriteLogType = LogType.Exception;

I think it’s good that the behavior can be customized, but it would be better to have the default behavior match what Unity does by default.

If this is acceptable, I would be happy to open a pull request for the work! 😁

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
neuecccommented, May 5, 2020

@randomPoison

In your example, the Throw from async Task is not captured. Normal tasks must be set explicitly via TaskScheduler.UnobservedTaskException. In other words, this is where we identify whether it’s Unobserved or not.

It’s also listed at the top in Error.

UnobservedTaskException:System.Exception: Thrown from `async UniTask` function
  at ExceptionExamples+<<ThrowFromUniTask>g__ThrowInner|7_0>d.MoveNext () [0x0006f] in C:\...\Scenes\ExceptionExamples.cs:72 

The problem, however, is that, as you say, the InnerException dump is Log-unfriendly in Unity. It’s a choice between making the Log jump friendly or marking it as Unobserved.

Now, I think most people don’t understand the meaning of Uobserved in the first place, and jump-friendly seems to benefit a lot of people. Ok, I’d like to make Exception the default, at least in v2.

2reactions
randomPoisoncommented, May 5, 2020

You’re right, there’s not a lot of harm in leaving that option in there, especially if it’s set to log using Debug.LogException() by default. However, there’s also not much value in leaving it in I think. It’s a bad practice to log exceptions with anything other than Debug.LogException(), so leaving that option in just allows users to make their projects harder to debug with no benefit. It also adds a bit of unnecessary code complexity to UniTaskScheduler. So even if there’s not much harm in leaving it, I only see benefits to removing it.

That said, once the default is changed to Debug.LogException() my main concern will be addressed! So it won’t matter a ton to me if you do leave it in.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging uncaught exceptions in Python
Use a custom logger with an example handler. This one changes the unhandled exception to go to stdout rather than stderr, but you...
Read more >
NET 6 breaking change: Exception handling in hosting - .NET
NET 6 breaking change in core .NET libraries where unhandled exceptions from a BackgroundService are logged instead of lost.
Read more >
Configure Django to log exceptions in production
Django default logging behaviour for unhandled exceptions is: # With DEBUG=True (Development). Log the exception on console/stream.
Read more >
Unhandled Exception Logging - Embrace.io
Embrace automatically logs all unhandled exceptions thrown by your application, ... By default, only exceptions thrown on the main Unity thread are logged....
Read more >
Logging uncaught exceptions in Python applications
One situation that you want to make sure you get in your logs is when an unhandled exception occurs in the program.
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