mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 08:20:00 +09:00
Merge branch 'master' into fix-leave-room-race-2
This commit is contained in:
@ -6,34 +6,11 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Extensions.ExceptionExtensions;
|
||||
using osu.Framework.Logging;
|
||||
|
||||
namespace osu.Game.Extensions
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Denote a task which is to be run without local error handling logic, where failure is not catastrophic.
|
||||
/// Avoids unobserved exceptions from being fired.
|
||||
/// </summary>
|
||||
/// <param name="task">The task.</param>
|
||||
/// <param name="logAsError">
|
||||
/// Whether errors should be logged as errors visible to users, or as debug messages.
|
||||
/// Logging as debug will essentially silence the errors on non-release builds.
|
||||
/// </param>
|
||||
public static Task CatchUnobservedExceptions(this Task task, bool logAsError = false)
|
||||
{
|
||||
return task.ContinueWith(t =>
|
||||
{
|
||||
Exception? exception = t.Exception?.AsSingular();
|
||||
if (logAsError)
|
||||
Logger.Error(exception, $"Error running task: {exception?.Message ?? "(unknown)"}", LoggingTarget.Runtime, true);
|
||||
else
|
||||
Logger.Log($"Error running task: {exception}", LoggingTarget.Runtime, LogLevel.Debug);
|
||||
}, TaskContinuationOptions.NotOnRanToCompletion);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a continuation to be performed only after the attached task has completed.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user