Skip to content

Commit

Permalink
Merge pull request #211 from smoogipoo/reduce-exceptions
Browse files Browse the repository at this point in the history
Reduce exceptions
  • Loading branch information
peppy authored Jan 31, 2024
2 parents 56158ec + 6f75d8d commit 0806da6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion osu.Server.Spectator/ConcurrentConnectionLimiter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,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");
throw new InvalidStateException($"State is not valid for this connection, context: {LoggingHubFilter.GetMethodCallDisplayString(invocationContext)})");
}

return await next(invocationContext);
Expand Down
9 changes: 6 additions & 3 deletions osu.Server.Spectator/Hubs/Spectator/SpectatorHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ public async Task BeginPlaySession(long? scoreToken, SpectatorState state)
clientState.State = state;
clientState.ScoreToken = scoreToken;

if (state.RulesetID == null) throw new ArgumentNullException(nameof(state.RulesetID));
if (state.BeatmapID == null) throw new ArgumentNullException(nameof(state.BeatmapID));
if (state.RulesetID == null)
return;

if (state.BeatmapID == null)
return;

using (var db = databaseFactory.GetInstance())
{
Expand All @@ -72,7 +75,7 @@ public async Task BeginPlaySession(long? scoreToken, SpectatorState state)
throw new ArgumentException(nameof(username));

if (string.IsNullOrEmpty(beatmap?.checksum))
throw new ArgumentException(nameof(state.BeatmapID));
return;

clientState.Score = new Score
{
Expand Down
6 changes: 3 additions & 3 deletions osu.Server.Spectator/LoggingHubFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class LoggingHubFilter : IHubFilter
try
{
if (DebugUtils.IsDebugBuild)
logTarget.Log($"Invoking hub method: {getMethodCallDisplayString(invocationContext)}", LogLevel.Debug);
logTarget.Log($"Invoking hub method: {GetMethodCallDisplayString(invocationContext)}", LogLevel.Debug);

return await next(invocationContext);
}
catch (Exception e)
{
logTarget.Error($"Failed to invoke hub method: {getMethodCallDisplayString(invocationContext)}", e);
logTarget.Error($"Failed to invoke hub method: {GetMethodCallDisplayString(invocationContext)}", e);
throw;
}
}
Expand Down Expand Up @@ -68,7 +68,7 @@ public async Task OnDisconnectedAsync(HubLifetimeContext context, Exception? exc
}
}

private static string getMethodCallDisplayString(HubInvocationContext invocationContext)
public static string GetMethodCallDisplayString(HubInvocationContext invocationContext)
{
var methodCall = $"{invocationContext.HubMethodName}({string.Join(", ", invocationContext.HubMethodArguments.Select(getReadableString))})";
return methodCall;
Expand Down
3 changes: 2 additions & 1 deletion osu.Server.Spectator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Net;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Hosting;
using osu.Framework.Logging;
using osu.Framework.Platform;
Expand Down Expand Up @@ -41,7 +42,7 @@ private static IHostBuilder createHostBuilder(string[] args)
{
webBuilder.UseSentry(o =>
{
o.AddExceptionFilterForType<ServerShuttingDownException>();
o.AddExceptionFilterForType<HubException>();
o.TracesSampleRate = 0.01;
#if !DEBUG
o.Dsn = "https://[email protected]/8";
Expand Down

0 comments on commit 0806da6

Please sign in to comment.