Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type of some exceptions so they're logged #216

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Moq;
using osu.Game.Online.Multiplayer;
using osu.Server.Spectator.Entities;
using osu.Server.Spectator.Hubs.Spectator;
using Xunit;
Expand Down Expand Up @@ -120,7 +119,7 @@ public async Task TestConcurrencyBlocked()
var firstInvocationContext = new HubInvocationContext(firstContextMock.Object, serviceProviderMock.Object, hubMock.Object,
typeof(SpectatorHub).GetMethod(nameof(SpectatorHub.StartWatchingUser))!, new object[] { 1234 });
// should throw.
await Assert.ThrowsAsync<InvalidStateException>(() => filter.InvokeMethodAsync(firstInvocationContext, _ => new ValueTask<object?>(new object())).AsTask());
await Assert.ThrowsAsync<InvalidOperationException>(() => filter.InvokeMethodAsync(firstInvocationContext, _ => new ValueTask<object?>(new object())).AsTask());
}

[Fact]
Expand Down
3 changes: 1 addition & 2 deletions osu.Server.Spectator/ConcurrentConnectionLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Logging;
using osu.Game.Online;
using osu.Game.Online.Multiplayer;
using osu.Server.Spectator.Entities;
using osu.Server.Spectator.Extensions;
using osu.Server.Spectator.Hubs;
Expand Down Expand Up @@ -102,7 +101,7 @@ private static void log(HubLifetimeContext context, string message)
bool connectionIsValid = tokenIdMatches && hubRegistered && connectionIdMatches;

if (!connectionIsValid)
throw new InvalidStateException($"State is not valid for this connection, context: {LoggingHubFilter.GetMethodCallDisplayString(invocationContext)})");
throw new InvalidOperationException($"State is not valid for this connection, context: {LoggingHubFilter.GetMethodCallDisplayString(invocationContext)})");
}

return await next(invocationContext);
Expand Down
6 changes: 3 additions & 3 deletions osu.Server.Spectator/Hubs/Multiplayer/MultiplayerHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task<MultiplayerRoom> JoinRoomWithPassword(long roomId, string pass
/// It should only be called by the room's host, before any other user has joined (and will throw if not).
/// </summary>
/// <param name="roomId">The proposed room ID.</param>
/// <exception cref="InvalidStateException">If anything is wrong with this request.</exception>
/// <exception cref="InvalidOperationException">If anything is wrong with this request.</exception>
private async Task<ServerMultiplayerRoom> retrieveRoom(long roomId)
{
Log($"Retrieving room {roomId} from database");
Expand All @@ -176,13 +176,13 @@ private async Task<ServerMultiplayerRoom> retrieveRoom(long roomId)
var databaseRoom = await db.GetRoomAsync(roomId);

if (databaseRoom == null)
throw new InvalidStateException("Specified match does not exist.");
throw new InvalidOperationException("Specified match does not exist.");

if (databaseRoom.ends_at != null && databaseRoom.ends_at < DateTimeOffset.Now)
throw new InvalidStateException("Match has already ended.");

if (databaseRoom.user_id != Context.GetUserId())
throw new InvalidStateException("Non-host is attempting to join match before host");
throw new InvalidOperationException("Non-host is attempting to join match before host");

var room = new ServerMultiplayerRoom(roomId, HubContext)
{
Expand Down
3 changes: 1 addition & 2 deletions osu.Server.Spectator/Hubs/StatefulUserHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Caching.Distributed;
using osu.Game.Online;
using osu.Game.Online.Multiplayer;
using osu.Server.Spectator.Entities;
using osu.Server.Spectator.Extensions;

Expand Down Expand Up @@ -113,7 +112,7 @@ protected async Task<ItemUsage<TUserState>> GetOrCreateLocalUserState()
if (usage.Item != null && usage.Item.ConnectionId != Context.ConnectionId)
{
usage.Dispose();
throw new InvalidStateException("State is not valid for this connection");
throw new InvalidOperationException("State is not valid for this connection");
}

return usage;
Expand Down
Loading