Skip to content

Commit

Permalink
Merge pull request #2966 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
Exception enhancement
  • Loading branch information
bao-qian authored May 19, 2020
2 parents 7219524 + dc737ab commit fe5f997
Show file tree
Hide file tree
Showing 37 changed files with 227 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Calculator/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"cxfksword",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Caculator.dll",
"IcoPath":"Images\\calculator.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Color/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Color.dll",
"IcoPath":"Images\\color.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.ControlPanel/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"CoenraadS",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.ControlPanel.dll",
"IcoPath":"Images\\ControlPanel.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Folder/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Folder.dll",
"IcoPath":"Images\\folder.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.PluginIndicator/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.PluginIndicator.dll",
"IcoPath":"Images\\work.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.PluginManagement/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.PluginManagement.dll",
"IcoPath":"Images\\plugin.png"
}
11 changes: 10 additions & 1 deletion Plugins/Wox.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public void Save()

public List<Result> Query(Query query)
{

if (_updateSource != null && !_updateSource.IsCancellationRequested)
{
_updateSource.Cancel();
Expand Down Expand Up @@ -99,7 +100,8 @@ public List<Result> Query(Query query)
if (token.IsCancellationRequested) { return new List<Result>(); }
OrderedParallelQuery<Result> sorted = resultRaw.AsParallel().OrderByDescending(r => r.Score);
List<Result> results = new List<Result>();
foreach (Result r in sorted) {
foreach (Result r in sorted)
{
if (token.IsCancellationRequested) { return new List<Result>(); }
var ignored = _settings.IgnoredSequence.Any(entry =>
{
Expand Down Expand Up @@ -137,6 +139,13 @@ public void Init(PluginInitContext context)
});
}

public void InitSync(PluginInitContext context)
{
_context = context;
loadSettings();
IndexPrograms();
}

public void loadSettings()
{
_settingsStorage = new PluginJsonStorage<Settings>();
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Program/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Program.dll",
"IcoPath":"Images\\program.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Shell/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Shell.dll",
"IcoPath":"Images\\shell.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Sys/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Sys.dll",
"IcoPath":"Images\\lock.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.Url/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Author":"Wox",
"Version":"1.0.0",
"Language":"csharp",
"Website":"http://www.wox.one/plugin",
"Website":"https://github.com/Wox-launcher/Wox",
"ExecuteFileName":"Wox.Plugin.Url.dll",
"IcoPath":"Images\\url.png"
}
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.WebSearch/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"Author": "Wox",
"Version": "1.0.0",
"Language": "csharp",
"Website": "http://www.wox.one/plugin",
"Website": "https://github.com/Wox-launcher/Wox",
"ExecuteFileName": "Wox.Plugin.WebSearch.dll",
"IcoPath": "Images\\web_search.png"
}
2 changes: 2 additions & 0 deletions Wox.Core/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
}
catch (Exception e)
{
e.Data.Add(nameof(configPath), configPath);
e.Data.Add(nameof(pluginDirectory), pluginDirectory);
Logger.WoxError($"invalid json for config <{configPath}>", e);
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public static void InitializePlugins(IPublicAPI api)
}
catch (Exception e)
{
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.Website), pair.Metadata.Website);
Logger.WoxError($"Fail to Init plugin: {pair.Metadata.Name}", e);
pair.Metadata.Disabled = true;
failedPlugins.Enqueue(pair);
Expand Down Expand Up @@ -186,6 +189,9 @@ public static List<Result> QueryForPlugin(PluginPair pair, Query query)
}
catch (Exception e)
{
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.Website), pair.Metadata.Website);
Logger.WoxError($"Exception for plugin <{pair.Metadata.Name}> when query <{query}>", e);
return new List<Result>();
}
Expand Down
9 changes: 9 additions & 0 deletions Wox.Core/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (Exception e)
{
e.Data.Add(nameof(metadata.ID), metadata.ID);
e.Data.Add(nameof(metadata.Name), metadata.Name);
e.Data.Add(nameof(metadata.Website), metadata.Website);
Logger.WoxError($"Couldn't load assembly for {metadata.Name}", e);
return;
}
Expand All @@ -63,6 +66,9 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (InvalidOperationException e)
{
e.Data.Add(nameof(metadata.ID), metadata.ID);
e.Data.Add(nameof(metadata.Name), metadata.Name);
e.Data.Add(nameof(metadata.Website), metadata.Website);
Logger.WoxError($"Can't find class implement IPlugin for <{metadata.Name}>", e);
return;
}
Expand All @@ -73,6 +79,9 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (Exception e)
{
e.Data.Add(nameof(metadata.ID), metadata.ID);
e.Data.Add(nameof(metadata.Name), metadata.Name);
e.Data.Add(nameof(metadata.Website), metadata.Website);
Logger.WoxError($"Can't create instance for <{metadata.Name}>", e);
return;
}
Expand Down
8 changes: 4 additions & 4 deletions Wox.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Logger.WoxError($"Check your connection and proxy settings to api.github.com.", e);
Logger.WoxError($"Check your connection and proxy settings to api.github.com. {e.Message}");
updateManager.Dispose();
return;
}
Expand All @@ -67,7 +67,7 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Logger.WoxError($"Check your connection and proxy settings to github-cloud.s3.amazonaws.com.", e);
Logger.WoxError($"Check your connection and proxy settings to github-cloud.s3.amazonaws.com. {e.Message}");
updateManager.Dispose();
return;
}
Expand All @@ -86,11 +86,11 @@ public async Task UpdateApp(bool silentIfLatestVersion = true, bool updateToPrer
}
catch (Exception e) when (e is HttpRequestException || e is WebException || e is SocketException)
{
Logger.WoxError($"Please check your connection and proxy settings to api.github.com.", e);
Logger.WoxError($"Please check your connection and proxy settings {e.Message}");
}
catch (Exception e)
{
Logger.WoxError($"cannot check update", e);
Logger.WoxError($"cannot check update {e.Message}");
}

}
Expand Down
18 changes: 16 additions & 2 deletions Wox.Infrastructure/Exception/ExceptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Xml;
using Microsoft.Win32;

namespace Wox.Infrastructure.Exception
{
public class ExceptionFormatter
{
private static string _systemLanguage;
private static string _woxLanguage;
public static void Initialize(string systemLanguage, string woxLanguage)
{
_systemLanguage = systemLanguage;
_woxLanguage = woxLanguage;
}
public static string FormattedException(System.Exception ex)
{
return FormattedAllExceptions(ex).ToString();
Expand Down Expand Up @@ -135,7 +144,10 @@ public static string RuntimeInfo()
sb.AppendLine($"* Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
sb.AppendLine($"* Wox version: {Constant.Version}");
sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}");
sb.AppendLine($"* x64: {Environment.Is64BitOperatingSystem}");
sb.AppendLine($"* x64 OS: {Environment.Is64BitOperatingSystem}");
sb.AppendLine($"* x64 Process: {Environment.Is64BitProcess}");
sb.AppendLine($"* System Language: {_systemLanguage}");
sb.AppendLine($"* Wox Language: {_woxLanguage}");
sb.AppendLine($"* CLR Version: {Environment.Version}");
sb.AppendLine($"* Installed .NET Framework: ");
foreach (var result in GetFrameworkVersionFromRegistry())
Expand All @@ -156,9 +168,11 @@ public static string SDKInfo()
return sb.ToString();
}

public static string ExceptionWithRuntimeInfo(System.Exception ex)
public static string ExceptionWithRuntimeInfo(System.Exception ex, string id)
{
StringBuilder sb = new StringBuilder();
sb.Append("Error id: ");
sb.AppendLine(id);
var formatted = FormattedAllExceptions(ex);
sb.Append(formatted);
var info = RuntimeInfoFull();
Expand Down
22 changes: 19 additions & 3 deletions Wox.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using Mindscape.Raygun4Net;
using NLog;
using NLog.Config;
using NLog.Targets;
using Sentry;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.UserSettings;

Expand All @@ -14,9 +14,10 @@ namespace Wox.Infrastructure.Logger
public static class Log
{
public const string DirectoryName = "Logs";
private static RaygunClient _raygunClient = new RaygunClient("LG5MX0YYMCpCN2AtD0fdZw");
public static string CurrentLogDirectory { get; }

private static string _woxLanguage = "not set";

static Log()
{
CurrentLogDirectory = Path.Combine(DataLocation.DataDirectory(), DirectoryName, Constant.Version);
Expand Down Expand Up @@ -74,10 +75,25 @@ public static void WoxError(this NLog.Logger logger, string message, System.Exce
{
Debug.WriteLine($"ERROR|{logger.Name}|{methodName}|{message}");
logger.Error($"{methodName}|{message}|{ExceptionFormatter.FormattedException(exception)}");
_raygunClient.Send(exception);
SendException(exception);
#if DEBUG
throw exception;
#endif
}

public static void updateSettingsInfo(string woxLanguage)
{
_woxLanguage = woxLanguage;

SentrySdk.ConfigureScope(scope =>
{
scope.SetTag("woxLanguage", _woxLanguage);
});
}

public static void SendException(System.Exception exception)
{
SentrySdk.CaptureException(exception);
}
}
}
10 changes: 7 additions & 3 deletions Wox.Infrastructure/UserSettings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ public static void Save()
}

private static WoxJsonStorage<Settings> _storage = new WoxJsonStorage<Settings>();
private static Settings _instance = _storage.Load();
public static Settings Instance => _instance;
public static Settings Instance;

#endregion
public static void Initialize()
{
Instance = _storage.Load();
}

#endregion

public string Hotkey { get; set; } = "Alt + Space";
public string Language { get; set; } = "en";
Expand Down
6 changes: 3 additions & 3 deletions Wox.Infrastructure/Wox.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell">
<Version>1.1.4</Version>
</PackageReference>
<PackageReference Include="Mindscape.Raygun4Net">
<Version>5.10.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
Expand All @@ -103,6 +100,9 @@
<PackageReference Include="NLog.Schema" GeneratePathProperty="true">
<Version>4.7.0</Version>
</PackageReference>
<PackageReference Include="Sentry">
<Version>2.1.1</Version>
</PackageReference>
<PackageReference Include="System.Runtime">
<Version>4.0.0</Version>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions Wox.Plugin/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public interface IContextMenu : IFeatures
List<Result> LoadContextMenus(Result selectedResult);
}

[Obsolete("If a plugin has a action keyword, then it is exclusive. This interface will be remove in v1.3.0")]
[Obsolete("If a plugin has a action keyword, then it is exclusive. This interface will be remove in v1.4.0")]
public interface IExclusiveQuery : IFeatures
{
[Obsolete("If a plugin has a action keyword, then it is exclusive. This method will be remove in v1.3.0")]
[Obsolete("If a plugin has a action keyword, then it is exclusive. This method will be remove in v1.4.0")]
bool IsExclusiveQuery(Query query);
}

Expand Down
2 changes: 1 addition & 1 deletion Wox.Plugin/Features/IContextMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IContextMenu instead, " +
"this method will be removed in v1.3.0")]
"this method will be removed in v1.4.0")]
public interface IContextMenu { }
}
2 changes: 1 addition & 1 deletion Wox.Plugin/Features/IExclusiveQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IInstantQuery instead, " +
"this method will be removed in v1.3.0")]
"this method will be removed in v1.4.0")]
public interface IExclusiveQuery { }
}
2 changes: 1 addition & 1 deletion Wox.Plugin/Features/IInstantQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Wox.Plugin.Features
{
[Obsolete("Delete Wox.Plugin.Features using directive, " +
"and use Wox.Plugin.Feature.IInstantQuery instead, " +
"this method will be removed in v1.3.0")]
"this method will be removed in v1.4.0")]
public interface IInstantQuery { }
}
Loading

0 comments on commit fe5f997

Please sign in to comment.