Skip to content

Commit c87bc8b

Browse files
authored
Merge pull request #27180 from bdach/better-submission-failure-messaging
Add better submission failure messaging
2 parents d7b1e3b + ec26ab5 commit c87bc8b

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

osu.Game/Screens/Play/SoloPlayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override GameplayLeaderboard CreateGameplayLeaderboard() =>
5252
Scores = { BindTarget = LeaderboardScores }
5353
};
5454

55-
protected override bool HandleTokenRetrievalFailure(Exception exception) => false;
55+
protected override bool ShouldExitOnTokenRetrievalFailure(Exception exception) => false;
5656

5757
protected override Task ImportScore(Score score)
5858
{

osu.Game/Screens/Play/SubmittingPlayer.cs

+24-15
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private bool handleTokenRetrieval()
118118
token = r.ID;
119119
tcs.SetResult(true);
120120
};
121-
req.Failure += handleTokenFailure;
121+
req.Failure += ex => handleTokenFailure(ex, displayNotification: true);
122122

123123
api.Queue(req);
124124

@@ -128,40 +128,49 @@ private bool handleTokenRetrieval()
128128

129129
return true;
130130

131-
void handleTokenFailure(Exception exception)
131+
void handleTokenFailure(Exception exception, bool displayNotification = false)
132132
{
133133
tcs.SetResult(false);
134134

135-
if (HandleTokenRetrievalFailure(exception))
135+
bool shouldExit = ShouldExitOnTokenRetrievalFailure(exception);
136+
137+
if (displayNotification || shouldExit)
136138
{
139+
string whatWillHappen = shouldExit
140+
? "Play in this state is not permitted."
141+
: "Your score will not be submitted.";
142+
137143
if (string.IsNullOrEmpty(exception.Message))
138-
Logger.Error(exception, "Failed to retrieve a score submission token.");
144+
Logger.Error(exception, $"Failed to retrieve a score submission token.\n\n{whatWillHappen}");
139145
else
140146
{
141147
switch (exception.Message)
142148
{
143-
case "expired token":
144-
Logger.Log("Score submission failed because your system clock is set incorrectly. Please check your system time, date and timezone.", level: LogLevel.Important);
149+
case @"missing token header":
150+
case @"invalid client hash":
151+
case @"invalid verification hash":
152+
Logger.Log($"Please ensure that you are using the latest version of the official game releases.\n\n{whatWillHappen}", level: LogLevel.Important);
153+
break;
154+
155+
case @"expired token":
156+
Logger.Log($"Your system clock is set incorrectly. Please check your system time, date and timezone.\n\n{whatWillHappen}", level: LogLevel.Important);
145157
break;
146158

147159
default:
148-
Logger.Log($"You are not able to submit a score: {exception.Message}", level: LogLevel.Important);
160+
Logger.Log($"{whatWillHappen} {exception.Message}", level: LogLevel.Important);
149161
break;
150162
}
151163
}
164+
}
152165

166+
if (shouldExit)
167+
{
153168
Schedule(() =>
154169
{
155170
ValidForResume = false;
156171
this.Exit();
157172
});
158173
}
159-
else
160-
{
161-
// Gameplay is allowed to continue, but we still should keep track of the error.
162-
// In the future, this should be visible to the user in some way.
163-
Logger.Log($"Score submission token retrieval failed ({exception.Message})");
164-
}
165174
}
166175
}
167176

@@ -170,7 +179,7 @@ void handleTokenFailure(Exception exception)
170179
/// </summary>
171180
/// <param name="exception">The error causing the failure.</param>
172181
/// <returns>Whether gameplay should be immediately exited as a result. Returning false allows the gameplay session to continue. Defaults to true.</returns>
173-
protected virtual bool HandleTokenRetrievalFailure(Exception exception) => true;
182+
protected virtual bool ShouldExitOnTokenRetrievalFailure(Exception exception) => true;
174183

175184
protected override async Task PrepareScoreForResultsAsync(Score score)
176185
{
@@ -231,7 +240,7 @@ private void submitFromFailOrQuit()
231240

232241
/// <summary>
233242
/// Construct a request to be used for retrieval of the score token.
234-
/// Can return null, at which point <see cref="HandleTokenRetrievalFailure"/> will be fired.
243+
/// Can return null, at which point <see cref="ShouldExitOnTokenRetrievalFailure"/> will be fired.
235244
/// </summary>
236245
[CanBeNull]
237246
protected abstract APIRequest<APIScoreToken> CreateTokenRequest();

osu.Game/Tests/Visual/TestPlayer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnF
6161
PauseOnFocusLost = pauseOnFocusLost;
6262
}
6363

64-
protected override bool HandleTokenRetrievalFailure(Exception exception) => false;
64+
protected override bool ShouldExitOnTokenRetrievalFailure(Exception exception) => false;
6565

6666
protected override APIRequest<APIScoreToken> CreateTokenRequest()
6767
{

0 commit comments

Comments
 (0)