From 447232fcf5ca24077bea6cc0b8901c89db79d4ba Mon Sep 17 00:00:00 2001 From: twopointzero Date: Thu, 16 Apr 2020 09:26:16 -0700 Subject: [PATCH] Add anonymized skin name to Sentry error reports. It is suspected that a great many exceptions occur during creation, modification, or general use of custom skins. While arbitrary anonymized skin names cannot be de-anonymized, we can at least determine the anonymized values for SimpleStyle and other well-known skins. And, while the name alone cannot tell us if the user has modified the skin, there is a great deal more likelihood of an actual application issue if we can tell the user is at least running SimpleStyle, under the assumption they've not modified it. If this new Sentry tagging still leaves too much ambiguity in error reports, especially those associated with SimpleStyle, we can add further detail (e.g. a hash of skin file content.) --- .../ErrorReporting/ErrorReporterTests.cs | 6 ++++ TJAPlayer3/Common/CSkin.cs | 5 +++ TJAPlayer3/ErrorReporting/ErrorReporter.cs | 34 ++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/TJAPlayer3.Tests/ErrorReporting/ErrorReporterTests.cs b/TJAPlayer3.Tests/ErrorReporting/ErrorReporterTests.cs index 9cefce107..891f6aa14 100644 --- a/TJAPlayer3.Tests/ErrorReporting/ErrorReporterTests.cs +++ b/TJAPlayer3.Tests/ErrorReporting/ErrorReporterTests.cs @@ -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) { diff --git a/TJAPlayer3/Common/CSkin.cs b/TJAPlayer3/Common/CSkin.cs index 9cfd9f8ef..9b34b0db9 100644 --- a/TJAPlayer3/Common/CSkin.cs +++ b/TJAPlayer3/Common/CSkin.cs @@ -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)); + } + /// /// スキンパス名をフルパスで取得する /// diff --git a/TJAPlayer3/ErrorReporting/ErrorReporter.cs b/TJAPlayer3/ErrorReporting/ErrorReporter.cs index 69b3559ab..835233c6c 100644 --- a/TJAPlayer3/ErrorReporting/ErrorReporter.cs +++ b/TJAPlayer3/ErrorReporting/ErrorReporter.cs @@ -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; @@ -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) { @@ -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 =