Skip to content

Commit

Permalink
Merge pull request #2977 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
adjust sentry info
  • Loading branch information
bao-qian authored May 20, 2020
2 parents b12097e + a5886d2 commit 443e89f
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 8 deletions.
3 changes: 0 additions & 3 deletions Plugins/Wox.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -191,6 +192,7 @@ public static List<Result> 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<Result>();
Expand Down
3 changes: 3 additions & 0 deletions Wox.Core/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> 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;
Expand All @@ -68,6 +69,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> 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;
Expand All @@ -81,6 +83,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> 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;
Expand Down
2 changes: 2 additions & 0 deletions Wox.Infrastructure/Exception/ExceptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Windows;
using System.Xml;
using Microsoft.Win32;
using Wox.Infrastructure.UserSettings;

namespace Wox.Infrastructure.Exception
{
Expand Down Expand Up @@ -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}");
Expand Down
18 changes: 17 additions & 1 deletion Wox.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,23 @@ public static void updateSettingsInfo(string woxLanguage)

public static void SendException(System.Exception exception)
{
SentrySdk.CaptureException(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;
SentrySdk.CaptureException(exception);
});
}
}
}
37 changes: 33 additions & 4 deletions Wox/Helper/ErrorReporting.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.CompilerServices;
Expand All @@ -10,6 +11,7 @@
using Sentry.Protocol;
using Wox.Infrastructure;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.UserSettings;

namespace Wox.Helper
{
Expand All @@ -26,7 +28,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());
Expand All @@ -35,7 +37,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(() =>
{
Expand All @@ -45,8 +47,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;
}
Expand All @@ -63,10 +65,37 @@ 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;
}

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 =>
{
scope.Level = SentryLevel.Fatal;
id = SentrySdk.CaptureException(exception);
});
return id.ToString();
}
}
}
5 changes: 5 additions & 0 deletions Wox/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down

0 comments on commit 443e89f

Please sign in to comment.