Skip to content

Commit

Permalink
Improve diagnostic message for unhandled exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Nov 4, 2024
1 parent c598719 commit 654be4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
7 changes: 2 additions & 5 deletions EndlessClient/GameExecution/EndlessGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ protected override void Update(GameTime gameTime)
}
}


protected override void Draw(GameTime gameTime)
{
var isTestMode = _controlSetRepository.CurrentControlSet.GameState == GameStates.TestMode;
Expand Down Expand Up @@ -308,10 +307,8 @@ private void ShowExceptionDetailDialog(Exception ex)
_contentProvider.Fonts[Constants.FontSize08pt5],
insertLineBreaks: true,
linkClickActions: [() => GithubIssueGenerator.FileIssue(ex)],
$"Client caused an exception: {ex.Message}",
ex.StackTrace,
$"Inner exception: {ex.InnerException?.Message ?? "(no inner exception)"}",
ex.InnerException?.StackTrace ?? "(no innner stacktrace)",
$"Client caused an exception",
ex.ToString(),
"*Report this exception as a GitHub issue");
dlg.ShowDialog();
}
Expand Down
45 changes: 22 additions & 23 deletions EndlessClient/GameExecution/GithubIssueGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.Encodings.Web;
using System.Text;
using System;
using System.Text.Encodings.Web;

namespace EndlessClient.GameExecution
{
Expand Down Expand Up @@ -33,8 +33,23 @@ private static string BuildIssueUrl(Exception ex)
{
var sb = new StringBuilder("https://github.com/ethanmoffat/EndlessClient/issues/new?");

sb.Append("labels=bug,userreport");
sb.Append($"&title=Unhandled+Client+Exception+Needs+Triage");
string crashMethod;
try
{
crashMethod = ex.InnerException == null
? ex.StackTrace.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1]
: ex.InnerException.StackTrace.Split(' ', StringSplitOptions.RemoveEmptyEntries)[1];
crashMethod = crashMethod[..crashMethod.IndexOf('(')];
}
catch
{
crashMethod = string.Empty;
}

var title = $"Unhandled+Client+Exception{(crashMethod == "" ? "" : $" in {crashMethod}")}";
sb.Append($"title={UrlEncoder.Default.Encode(title)}");

sb.Append("&labels=bug,userreport");
sb.Append("&assignees=ethanmoffat");

var body = @$"Thank you for your report! Please fill in the following information to help me better triage/resolve this issue.
Expand All @@ -50,26 +65,10 @@ private static string BuildIssueUrl(Exception ex)
**Expected behavior (other than it not crashing)?**
<Answer>
*Diagnostic Information added automatically. Please do not delete!*
**Exception message**: {ex.Message}
**Stack Trace**:
```
{ex.StackTrace}
```";

if (ex.InnerException != null)
{
body += @$"
**Diagnostic Information**
**Inner Exception**: {ex.InnerException.Message}
**Stack Trace**:
```
{ex.InnerException.StackTrace}
```
{ex}
";
}

var encoded = UrlEncoder.Default.Encode(body);
sb.Append($"&body={encoded}");

Expand Down

0 comments on commit 654be4b

Please sign in to comment.