From c2e60fdd9ea8956554664fcf6943a136ada678d8 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 May 2020 23:26:43 +0800 Subject: [PATCH 1/5] adjust crash level --- Wox.Infrastructure/Logger/Log.cs | 6 +++++- Wox/Helper/ErrorReporting.cs | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 359726856..b91909342 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -101,7 +101,11 @@ public static void updateSettingsInfo(string woxLanguage) public static void SendException(System.Exception exception) { - SentrySdk.CaptureException(exception); + SentrySdk.WithScope(scope => + { + scope.Level = Sentry.Protocol.SentryLevel.Error; + SentrySdk.CaptureException(exception); + }); } } } \ No newline at end of file diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs index efd7e2791..a7f4b20e0 100644 --- a/Wox/Helper/ErrorReporting.cs +++ b/Wox/Helper/ErrorReporting.cs @@ -26,7 +26,7 @@ private static void Report(Exception e, string id, [CallerMemberName] string met public static void UnhandledExceptionHandleTask(Task t) { - SentryId id = SentrySdk.CaptureException(t.Exception); + string id = SendException(t.Exception); Application.Current.Dispatcher.Invoke(() => { Report(t.Exception, id.ToString()); @@ -35,7 +35,7 @@ public static void UnhandledExceptionHandleTask(Task t) public static void UnhandledExceptionHandleMain(object sender, UnhandledExceptionEventArgs e) { - SentryId id = SentrySdk.CaptureException(e.ExceptionObject as Exception); + string id = SendException(e.ExceptionObject as Exception); //handle non-ui main thread exceptions Application.Current.Dispatcher.Invoke(() => { @@ -45,8 +45,8 @@ public static void UnhandledExceptionHandleMain(object sender, UnhandledExceptio public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - SentryId id = SentrySdk.CaptureException(e.Exception); - Report(e.Exception, id.ToString()); + string id = SendException(e.Exception); + Report(e.Exception, id); //prevent application exist, so the user can copy prompted error info e.Handled = true; } @@ -68,5 +68,16 @@ public static IDisposable InitializedSentry(string systemLanguage) }); return s; } + + public static string SendException(Exception exception) + { + SentryId id = SentryId.Empty; + SentrySdk.WithScope(scope => + { + scope.Level = SentryLevel.Fatal; + id = SentrySdk.CaptureException(exception); + }); + return id.ToString(); + } } } From 56f73a712126282e4812c97ea1e303034bbfc5e1 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 May 2020 23:32:10 +0800 Subject: [PATCH 2/5] add plugin directory info --- Wox.Core/Plugin/PluginManager.cs | 2 ++ Wox.Core/Plugin/PluginsLoader.cs | 3 +++ Wox/ReportWindow.xaml.cs | 5 +++++ 3 files changed, 10 insertions(+) diff --git a/Wox.Core/Plugin/PluginManager.cs b/Wox.Core/Plugin/PluginManager.cs index ce40d1e70..1cd5e971d 100644 --- a/Wox.Core/Plugin/PluginManager.cs +++ b/Wox.Core/Plugin/PluginManager.cs @@ -125,6 +125,7 @@ public static void InitializePlugins(IPublicAPI api) { e.Data.Add(nameof(pair.Metadata.ID), pair.Metadata.ID); e.Data.Add(nameof(pair.Metadata.Name), pair.Metadata.Name); + e.Data.Add(nameof(pair.Metadata.PluginDirectory), pair.Metadata.PluginDirectory); e.Data.Add(nameof(pair.Metadata.Website), pair.Metadata.Website); Logger.WoxError($"Fail to Init plugin: {pair.Metadata.Name}", e); pair.Metadata.Disabled = true; @@ -191,6 +192,7 @@ public static List QueryForPlugin(PluginPair pair, Query query) { e.Data.Add(nameof(pair.Metadata.ID), pair.Metadata.ID); e.Data.Add(nameof(pair.Metadata.Name), pair.Metadata.Name); + e.Data.Add(nameof(pair.Metadata.PluginDirectory), pair.Metadata.PluginDirectory); e.Data.Add(nameof(pair.Metadata.Website), pair.Metadata.Website); Logger.WoxError($"Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e); return new List(); diff --git a/Wox.Core/Plugin/PluginsLoader.cs b/Wox.Core/Plugin/PluginsLoader.cs index 5f1233a95..365109bf0 100644 --- a/Wox.Core/Plugin/PluginsLoader.cs +++ b/Wox.Core/Plugin/PluginsLoader.cs @@ -54,6 +54,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Couldn't load assembly for {metadata.Name}", e); return; @@ -68,6 +69,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Can't find class implement IPlugin for <{metadata.Name}>", e); return; @@ -81,6 +83,7 @@ public static IEnumerable CSharpPlugins(List source) { e.Data.Add(nameof(metadata.ID), metadata.ID); e.Data.Add(nameof(metadata.Name), metadata.Name); + e.Data.Add(nameof(metadata.PluginDirectory), metadata.PluginDirectory); e.Data.Add(nameof(metadata.Website), metadata.Website); Logger.WoxError($"Can't create instance for <{metadata.Name}>", e); return; diff --git a/Wox/ReportWindow.xaml.cs b/Wox/ReportWindow.xaml.cs index 5866d2d67..30a7858fa 100644 --- a/Wox/ReportWindow.xaml.cs +++ b/Wox/ReportWindow.xaml.cs @@ -38,6 +38,11 @@ private void SetException(Exception exception, string id) { paragraph.Inlines.Add($"Plugin Name {exception.Data[nameKey]}"); } + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + paragraph.Inlines.Add($"Plugin Directory {exception.Data[pluginDiretoryKey]}"); + } string idKey = nameof(Plugin.PluginPair.Metadata.ID); if (exception.Data.Contains(idKey)) { From 1589637a86400509eb1d92621ab1621e790be27b Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 May 2020 23:42:19 +0800 Subject: [PATCH 3/5] do not collect debug binary and 3rd plugin info --- Wox.Infrastructure/Logger/Log.cs | 12 ++++++++++++ Wox/Helper/ErrorReporting.cs | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index b91909342..2ec678519 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -101,6 +101,18 @@ public static void updateSettingsInfo(string woxLanguage) public static void SendException(System.Exception exception) { + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + string pluginDirectory = exception.Data[pluginDiretoryKey] as string; + bool debug = pluginDirectory.Contains(@"\Output\Release") || pluginDirectory.Contains(@"\Output\Release"); + bool thirdParty = !pluginDirectory.Contains(Constant.ProgramDirectory); + if (debug || thirdParty) + { + return; + } + } + SentrySdk.WithScope(scope => { scope.Level = Sentry.Protocol.SentryLevel.Error; diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs index a7f4b20e0..65b7e3707 100644 --- a/Wox/Helper/ErrorReporting.cs +++ b/Wox/Helper/ErrorReporting.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Net; using System.Net.Sockets; using System.Runtime.CompilerServices; @@ -71,6 +72,18 @@ public static IDisposable InitializedSentry(string systemLanguage) public static string SendException(Exception exception) { + string pluginDiretoryKey = nameof(Plugin.PluginPair.Metadata.PluginDirectory); + if (exception.Data.Contains(pluginDiretoryKey)) + { + string pluginDirectory = exception.Data[pluginDiretoryKey] as string; + bool debug = pluginDirectory.Contains(@"\Output\Release") || pluginDirectory.Contains(@"\Output\Release"); + bool thirdParty = !pluginDirectory.Contains(Constant.ProgramDirectory); + if (debug || thirdParty) + { + return SentryId.Empty.ToString(); + } + } + SentryId id = SentryId.Empty; SentrySdk.WithScope(scope => { From 3d102542a1aa552a114f7274ef5a2d078ceb90f6 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 May 2020 23:42:27 +0800 Subject: [PATCH 4/5] remove useless code --- Plugins/Wox.Plugin.Program/Main.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Main.cs b/Plugins/Wox.Plugin.Program/Main.cs index c01cd8dbe..411560030 100644 --- a/Plugins/Wox.Plugin.Program/Main.cs +++ b/Plugins/Wox.Plugin.Program/Main.cs @@ -12,15 +12,12 @@ using Wox.Infrastructure.Storage; using Wox.Plugin.Program.Programs; using Wox.Plugin.Program.Views; -using Stopwatch = Wox.Infrastructure.Stopwatch; using System.Threading; -using Windows.ApplicationModel.Background; namespace Wox.Plugin.Program { public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable, IReloadable { - private static readonly object IndexLock = new object(); internal static Win32[] _win32s { get; set; } internal static UWP.Application[] _uwps { get; set; } internal static Settings _settings { get; set; } From a5886d200fc762ab43dfe70d680861aeac37f253 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Wed, 20 May 2020 23:58:51 +0800 Subject: [PATCH 5/5] collect portable mode --- Wox.Infrastructure/Exception/ExceptionFormatter.cs | 2 ++ Wox/Helper/ErrorReporting.cs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/Wox.Infrastructure/Exception/ExceptionFormatter.cs b/Wox.Infrastructure/Exception/ExceptionFormatter.cs index 904be0770..707e91e40 100644 --- a/Wox.Infrastructure/Exception/ExceptionFormatter.cs +++ b/Wox.Infrastructure/Exception/ExceptionFormatter.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Xml; using Microsoft.Win32; +using Wox.Infrastructure.UserSettings; namespace Wox.Infrastructure.Exception { @@ -141,6 +142,7 @@ public static string RuntimeInfo() StringBuilder sb = new StringBuilder(); sb.AppendLine("## Runtime Info"); sb.AppendLine($"* Command Line: {Environment.CommandLine}"); + sb.AppendLine($"* Portable Mode: {DataLocation.PortableDataLocationInUse()}"); sb.AppendLine($"* Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}"); sb.AppendLine($"* Wox version: {Constant.Version}"); sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}"); diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs index 65b7e3707..4dd711fe6 100644 --- a/Wox/Helper/ErrorReporting.cs +++ b/Wox/Helper/ErrorReporting.cs @@ -11,6 +11,7 @@ using Sentry.Protocol; using Wox.Infrastructure; using Wox.Infrastructure.Exception; +using Wox.Infrastructure.UserSettings; namespace Wox.Helper { @@ -64,8 +65,12 @@ public static IDisposable InitializedSentry(string systemLanguage) }); SentrySdk.ConfigureScope(scope => { + scope.SetExtra("commandLine", Environment.CommandLine); + scope.SetExtra("portableMode", DataLocation.PortableDataLocationInUse()); scope.SetTag("systemLanguage", systemLanguage); scope.SetTag("timezone", TimeZoneInfo.Local.DisplayName); + scope.SetExtra("x64OS", Environment.Is64BitOperatingSystem); + scope.SetExtra("x64Process", Environment.Is64BitProcess); }); return s; }