Skip to content

Commit

Permalink
Log first change exception
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-qian committed May 15, 2016
1 parent 3c5511f commit 03a8a03
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ paket-files/
*.VC.db

## Wox specific

Output/*
/Python.Runtime.dll
Wox/Images/websearch/Thumbs.db
Wox/Images/Thumbs.db
Expand Down
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.CMD/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public List<Result> Query(Query query)
}
catch (Exception e)
{
Log.Error(e);
Log.Exception(e);
}
return results;
}
Expand Down
6 changes: 3 additions & 3 deletions Plugins/Wox.Plugin.PluginManagement/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private List<Result> ResultForInstallPlugin(Query query)
catch (WebException e)
{
Log.Warn("Can't connect to Wox plugin website, check your conenction");
Log.Error(e);
Log.Exception(e);
return new List<Result>();
}
List<WoxPluginResult> searchedPlugins;
Expand All @@ -129,7 +129,7 @@ private List<Result> ResultForInstallPlugin(Query query)
catch(JsonSerializationException e)
{
context.API.ShowMsg("Coundn't parse api search results", "Please update your Wox!", string.Empty);
Log.Error(e);
Log.Exception(e);
return results;
}

Expand Down Expand Up @@ -164,7 +164,7 @@ private List<Result> ResultForInstallPlugin(Query query)
var info = "download plugin " + r.name + "failed.";
MessageBox.Show(info);
Log.Warn(info);
Log.Error(e);
Log.Exception(e);
return false;
}
context.API.InstallPlugin(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void ReadAppPaths(string rootpath, List<Program> list)
}
catch (Exception e)
{
Log.Error(e);
Log.Exception(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void GetAppFromDirectory(string path, List<Program> list, int depth)
catch (Exception e)
{
var woxPluginException = new WoxPluginException("Program", $"GetAppFromDirectory failed: {path}", e);
Log.Error(woxPluginException);
Log.Exception(woxPluginException);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Plugins/Wox.Plugin.WebSearch/SuggestionSources/Baidu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override async Task<List<string>> GetSuggestions(string query)
catch (WebException e)
{
Log.Warn("Can't get suggestion from baidu");
Log.Error(e);
Log.Exception(e);
return new List<string>(); ;
}

Expand All @@ -45,7 +45,7 @@ public override async Task<List<string>> GetSuggestions(string query)
}
catch (JsonSerializationException e)
{
Log.Error(e);
Log.Exception(e);
return new List<string>();
}

Expand Down
4 changes: 2 additions & 2 deletions Plugins/Wox.Plugin.WebSearch/SuggestionSources/Google.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override async Task<List<string>> GetSuggestions(string query)
catch (WebException e)
{
Log.Warn("Can't get suggestion from google");
Log.Error(e);
Log.Exception(e);
return new List<string>(); ;
}
if (string.IsNullOrEmpty(result)) return new List<string>();
Expand All @@ -35,7 +35,7 @@ public override async Task<List<string>> GetSuggestions(string query)
}
catch (JsonSerializationException e)
{
Log.Error(e);
Log.Exception(e);
return new List<string>();
}
if (json != null)
Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Plugin/JsonRPCPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public List<Result> Query(Query query)
}
catch (Exception e)
{
Log.Error(e);
Log.Exception(e);
}
}
return null;
Expand Down
6 changes: 3 additions & 3 deletions Wox.Core/Plugin/PluginConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ private static PluginMetadata GetPluginMetadata(string pluginDirectory)
catch (Exception e)
{
string msg = $"Parse plugin config {configPath} failed: json format is not valid";
Log.Error(new WoxException(msg));
Log.Exception(new WoxException(msg));
return null;
}


if (!AllowedLanguage.IsAllowed(metadata.Language))
{
string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
Log.Error(new WoxException(msg));
Log.Exception(new WoxException(msg));
return null;
}

if (!File.Exists(metadata.ExecuteFilePath))
{
string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
Log.Error(new WoxException(msg));
Log.Exception(new WoxException(msg));
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public static List<Result> GetContextMenusForPlugin(Result result)
}
catch (Exception e)
{
Log.Error(new WoxPluginException(metadata.Name, "Couldn't load plugin context menus", e));
Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load plugin context menus", e));
return new List<Result>();
}
}
Expand Down
12 changes: 6 additions & 6 deletions Wox.Core/Plugin/PluginsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (Exception e)
{
Log.Error(new WoxPluginException(metadata.Name, "Couldn't load assembly", e));
Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load assembly", e));
continue;
}
var types = assembly.GetTypes();
Expand All @@ -50,7 +50,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (InvalidOperationException e)
{
Log.Error(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e));
Log.Exception(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e));
continue;
}
IPlugin plugin;
Expand All @@ -60,7 +60,7 @@ public static IEnumerable<PluginPair> CSharpPlugins(List<PluginMetadata> source)
}
catch (Exception e)
{
Log.Error(new WoxPluginException(metadata.Name, "Can't create instance", e));
Log.Exception(new WoxPluginException(metadata.Name, "Can't create instance", e));
continue;
}
PluginPair pair = new PluginPair
Expand Down Expand Up @@ -90,13 +90,13 @@ public static IEnumerable<PluginPair> PythonPlugins(List<PluginMetadata> source,
}
else
{
Log.Error(new WoxException("Python can't be found in PATH."));
Log.Exception(new WoxException("Python can't be found in PATH."));
return new List<PluginPair>();
}
}
else
{
Log.Error(new WoxException("Path variable is not set."));
Log.Exception(new WoxException("Path variable is not set."));
return new List<PluginPair>();
}
}
Expand All @@ -109,7 +109,7 @@ public static IEnumerable<PluginPair> PythonPlugins(List<PluginMetadata> source,
}
else
{
Log.Error(new WoxException("Can't find python executable in python directory"));
Log.Exception(new WoxException("Can't find python executable in python directory"));
return new List<PluginPair>();
}
}
Expand Down
4 changes: 2 additions & 2 deletions Wox.Core/Resource/Internationalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void MakesureDirectoriesExist()
}
catch (Exception e)
{
Log.Error(e);
Log.Exception(e);
}
}
}
Expand Down Expand Up @@ -117,7 +117,7 @@ internal void UpdatePluginMetadataTranslations(PluginPair pluginPair)
catch (Exception e)
{
var woxPluginException = new WoxPluginException(pluginPair.Metadata.Name, "Update Plugin metadata translation failed:", e);
Log.Error(woxPluginException);
Log.Exception(woxPluginException);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Wox.Core/Resource/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void MakesureThemeDirectoriesExist()
}
catch (Exception e)
{
Log.Error(e);
Log.Exception(e);
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Wox.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ await UpdateManager.GitHubUpdateManager(Infrastructure.Wox.Github, urlDownloader
}
catch (HttpRequestException he)
{
Log.Error(he);
Log.Exception(he);
}
catch (WebException we)
{
Log.Error(we);
Log.Exception(we);
}
catch (SocketException sc)
{
Log.Info("Socket exception happened!, which method cause this exception??");
Log.Error(sc);
Log.Exception(sc);
}
catch (Exception exception)
{
Expand Down Expand Up @@ -72,7 +72,7 @@ public static async Task<string> NewVersion()
catch (WebException e)
{
Log.Warn("Can't connect to github api to check new version");
Log.Error(e);
Log.Exception(e);
return string.Empty;
}

Expand All @@ -85,7 +85,7 @@ public static async Task<string> NewVersion()
}
catch (JsonSerializationException e)
{
Log.Error(e);
Log.Exception(e);
return string.Empty;
}
var version = json?["tag_name"]?.ToString();
Expand Down
4 changes: 2 additions & 2 deletions Wox.Infrastructure/Image/ImageLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static ImageSource ShellIcon(string fileName)
}
catch (System.Exception e)
{
Log.Error(e);
Log.Exception(e);
return ImageSources[ErrorIcon];
}
}
Expand Down Expand Up @@ -94,7 +94,7 @@ private static ImageSource AssociatedIcon(string path)
}
catch (System.Exception e)
{
Log.Error(e);
Log.Exception(e);
return ImageSources[ErrorIcon];
}
}
Expand Down
18 changes: 14 additions & 4 deletions Wox.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,29 @@ private static string CallerType()
var type = $"{method.DeclaringType.NonNull().FullName}.{method.Name}";
return type;
}
public static void Error(System.Exception e)

public static void Error(string msg)
{
var type = CallerType();
var logger = LogManager.GetLogger(type);
System.Diagnostics.Debug.WriteLine($"ERROR: {msg}");
logger.Error(msg);
}

public static void Exception(System.Exception e)
{
#if DEBUG
throw e;
#else
while (e.InnerException != null)
var type = CallerType();
var logger = LogManager.GetLogger(type);

do
{
logger.Error(e.Message);
logger.Error(e.StackTrace);
logger.Error($"\n{e.StackTrace}");
e = e.InnerException;
}
} while (e != null);
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions Wox.Infrastructure/Storage/BinaryStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ private void Deserialize(FileStream stream)
}
catch (SerializationException e)
{
Log.Error(e);
Log.Exception(e);
LoadDefault();
}
catch (InvalidCastException e)
{
Log.Error(e);
Log.Exception(e);
LoadDefault();
}
finally
Expand Down Expand Up @@ -114,7 +114,7 @@ public override void Save()
}
catch (SerializationException e)
{
Log.Error(e);
Log.Exception(e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Wox.Infrastructure/Storage/JsonStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void Deserialize(string searlized)
catch (JsonSerializationException e)
{
LoadDefault();
Log.Error(e);
Log.Exception(e);
}
}

Expand Down
23 changes: 19 additions & 4 deletions Wox/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Wox.Core.UserSettings;
using Wox.Helper;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using Wox.ViewModel;
using Stopwatch = Wox.Infrastructure.Stopwatch;
Expand All @@ -22,7 +23,8 @@ public partial class App : IDisposable, ISingleInstanceApp
[STAThread]
public static void Main()
{
RegisterAppDomainUnhandledException();
RegisterAppDomainExceptions();

if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
using (var application = new App())
Expand Down Expand Up @@ -74,18 +76,31 @@ private void RegisterExitEvents()
Current.Exit += (s, e) => Dispose();
Current.SessionEnding += (s, e) => Dispose();
}

/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private void RegisterDispatcherUnhandledException()
{
// let exception throw as normal is better for Debug
DispatcherUnhandledException += ErrorReporting.DispatcherUnhandledException;
}



/// <summary>
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainUnhandledException()
private static void RegisterAppDomainExceptions()
{
// let exception throw as normal is better for Debug

AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
AppDomain.CurrentDomain.FirstChanceException += (s, e) =>
{
Log.Error("First Chance Exception:");
Log.Exception(e.Exception);
};
}

public void Dispose()
Expand Down
Loading

0 comments on commit 03a8a03

Please sign in to comment.