1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 16:37:26 +08:00

Merge pull request #11622 from peppy/remove-unobserved-exception-handling

Remove all usage of CatchUnobservedExceptions
This commit is contained in:
Dan Balasescu 2021-01-29 19:31:07 +09:00 committed by GitHub
commit cd8ef5373d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 51 deletions

View File

@ -1,36 +0,0 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using System;
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 void CatchUnobservedExceptions(this Task task, bool logAsError = false)
{
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);
}
}
}

View File

@ -15,7 +15,6 @@ using osu.Framework.Graphics;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
@ -104,7 +103,7 @@ namespace osu.Game.Online.Multiplayer
if (!connected.NewValue && Room != null) if (!connected.NewValue && Room != null)
{ {
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important); Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
LeaveRoom().CatchUnobservedExceptions(); LeaveRoom();
} }
}); });
} }

View File

@ -4,7 +4,6 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Extensions;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
@ -23,7 +22,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.OnResuming(last); base.OnResuming(last);
if (client.Room != null) if (client.Room != null)
client.ChangeState(MultiplayerUserState.Idle).CatchUnobservedExceptions(true); client.ChangeState(MultiplayerUserState.Idle);
} }
protected override void UpdatePollingRate(bool isIdle) protected override void UpdatePollingRate(bool isIdle)

View File

@ -11,7 +11,6 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Extensions;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components; using osu.Game.Screens.OnlinePlay.Components;
@ -237,7 +236,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
// accessing Exception here silences any potential errors from the antecedent task // accessing Exception here silences any potential errors from the antecedent task
if (t.Exception != null) if (t.Exception != null)
{ {
t.CatchUnobservedExceptions(true); // will run immediately.
// gameplay was not started due to an exception; unblock button. // gameplay was not started due to an exception; unblock button.
endOperation(); endOperation();
} }
@ -248,11 +246,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
} }
client.ToggleReady() client.ToggleReady()
.ContinueWith(t => .ContinueWith(t => endOperation());
{
t.CatchUnobservedExceptions(true); // will run immediately.
endOperation();
});
void endOperation() void endOperation()
{ {

View File

@ -9,7 +9,6 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.ExceptionExtensions; using osu.Framework.Extensions.ExceptionExtensions;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Game.Extensions;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Online.Rooms.RoomStatuses;
@ -69,7 +68,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
base.PartRoom(); base.PartRoom();
multiplayerClient.LeaveRoom().CatchUnobservedExceptions(); multiplayerClient.LeaveRoom();
// Todo: This is not the way to do this. Basically when we're the only participant and the room closes, there's no way to know if this is actually the case. // Todo: This is not the way to do this. Basically when we're the only participant and the room closes, there's no way to know if this is actually the case.
// This is delayed one frame because upon exiting the match subscreen, multiplayer updates the polling rate and messes with polling. // This is delayed one frame because upon exiting the match subscreen, multiplayer updates the polling rate and messes with polling.

View File

@ -10,7 +10,6 @@ using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Extensions;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -176,7 +175,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants
if (Room.Host?.UserID != api.LocalUser.Value.Id) if (Room.Host?.UserID != api.LocalUser.Value.Id)
return; return;
Client.TransferHost(targetUser).CatchUnobservedExceptions(true); Client.TransferHost(targetUser);
}) })
}; };
} }