Merge branch 'master' into fix-leave-room-race-2

This commit is contained in:
Bartłomiej Dach
2021-01-30 13:41:04 +01:00
100 changed files with 1448 additions and 587 deletions

View File

@ -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>