Skip to content

Commit

Permalink
Merge pull request #35 from twopointzero/feature/add-skin-name-to-sen…
Browse files Browse the repository at this point in the history
…try-errors

Add anonymized skin name to Sentry error reports.
  • Loading branch information
twopointzero committed Apr 16, 2020
2 parents 413710b + 447232f commit c653e2c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
6 changes: 6 additions & 0 deletions TJAPlayer3.Tests/ErrorReporting/ErrorReporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace TJAPlayer3.Tests.ErrorReporting
public sealed class ErrorReporterTests
{
[Test]
[TestCase(ErrorReporter.GetCurrentSkinNameOrNullFallbackForNullSkin, "dX+hmseHos63UjL7n6bocIEgSZxo+qZ1szIFljYJf0k=")]
[TestCase(ErrorReporter.GetCurrentSkinNameOrNullFallbackForExceptionEncountered, "RJ1TZ22uELG4WVEWkfitV2PGE6xjdzoY4zXYqQvS/UY=")]
[TestCase("", "47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")]
[TestCase(" ", "Nqnn8clbgv+5l0PgxcTOldg8mkMKrFn4TvPL+rYUUGg=")]
[TestCase("Default", "IbERy/5uj8otGBxD9TrVSLIuOKypVbmCRwalBLCgei0=")]
[TestCase("SimpleStyle", "U6QVPvJpFuDf1y6cxYbW9D+LvrG7PYLVFwDRY4xdLeM=")]
[TestCase("This is only a test", "pPi+NdUkNVp81f+/9Vi7dvgVdtr6f6WpdqqjVD8ptCo=")]
public void TestToSha256InBase64(string input, string expected)
{
Expand Down
5 changes: 5 additions & 0 deletions TJAPlayer3/Common/CSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ public string[] strBoxDefSkinSubfolders
private static string strSystemSkinSubfolderFullName; // Config画面で設定されたスキン
private static string strBoxDefSkinSubfolderFullName = ""; // box.defで指定されているスキン

public string GetCurrentSkinName(bool fromUserConfig = false)
{
return GetSkinName(TJAPlayer3.Skin.GetCurrentSkinSubfolderFullName(fromUserConfig));
}

/// <summary>
/// スキンパス名をフルパスで取得する
/// </summary>
Expand Down
34 changes: 33 additions & 1 deletion TJAPlayer3/ErrorReporting/ErrorReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public static class ErrorReporter
private const string EnvironmentDevelopment = "development";
private const string EnvironmentProduction = "production";

public const string GetCurrentSkinNameOrNullFallbackForNullSkin = "[GetCurrentSkinNameOrNull null skin]";
public const string GetCurrentSkinNameOrNullFallbackForExceptionEncountered = "[GetCurrentSkinNameOrNull exception encountered]";

public static void WithErrorReporting(Action action)
{
var appInformationalVersion = TJAPlayer3.AppInformationalVersion;
Expand Down Expand Up @@ -101,7 +104,16 @@ private static void ReportError(Exception e)
#if !DEBUG
try
{
SentrySdk.CaptureException(e);
SentrySdk.WithScope(scope =>
{
var skinName = GetCurrentSkinNameOrNull();
if (skinName != null)
{
scope.SetTag("skin.name", ToSha256InBase64(skinName));
}
SentrySdk.CaptureException(e);
});
}
catch (TimeoutException)
{
Expand All @@ -114,6 +126,26 @@ private static void ReportError(Exception e)
#endif
}

private static string GetCurrentSkinNameOrNull()
{
try
{
var skin = TJAPlayer3.Skin;
if (skin == null)
{
return GetCurrentSkinNameOrNullFallbackForNullSkin;
}

return skin.GetCurrentSkinName();
}
catch (Exception e)
{
Trace.WriteLine("Unexpected exception encountered when attempting to get the current skin name: " + e);

return GetCurrentSkinNameOrNullFallbackForExceptionEncountered;
}
}

private static void NotifyUserOfError(Exception exception)
{
var messageBoxText =
Expand Down

0 comments on commit c653e2c

Please sign in to comment.