Better exception report.

This commit is contained in:
qianlifeng
2015-01-16 23:42:12 +08:00
parent 32e0074f26
commit 9d39b616f9
12 changed files with 98 additions and 80 deletions

View File

@@ -10,21 +10,19 @@ namespace Wox.Core.Exception
{
public class ExceptionFormatter
{
public static string FormatExcpetion(object exception)
public static string FormatExcpetion(System.Exception exception)
{
return CreateExceptionReport(exception);
}
private static string CreateExceptionReport(object exceptionObject)
private static string CreateExceptionReport(System.Exception ex)
{
var sb = new StringBuilder();
sb.AppendLine();
sb.AppendLine("## Exception");
sb.AppendLine();
sb.AppendLine("```");
var ex = exceptionObject as System.Exception;
if (ex != null)
{
var exlist = new List<StringBuilder>();
while (ex != null)
@@ -59,14 +57,6 @@ namespace Wox.Core.Exception
}
sb.AppendLine("```");
sb.AppendLine();
}
else
{
sb.AppendLine(exceptionObject.GetType().FullName);
sb.AppendLine(new StackTrace().ToString());
sb.AppendLine("```");
sb.AppendLine();
}
sb.AppendLine("## Environment");
sb.AppendLine();
@@ -88,9 +78,9 @@ namespace Wox.Core.Exception
}
sb.AppendLine();
sb.AppendLine("## Assemblies - " + System.AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine("## Assemblies - " + AppDomain.CurrentDomain.FriendlyName);
sb.AppendLine();
foreach (var ass in System.AppDomain.CurrentDomain.GetAssemblies().OrderBy(o => o.GlobalAssemblyCache ? 100 : 0))
foreach (var ass in AppDomain.CurrentDomain.GetAssemblies().OrderBy(o => o.GlobalAssemblyCache ? 50 : 0))
{
sb.Append("* ");
sb.Append(ass.FullName);
@@ -99,38 +89,6 @@ namespace Wox.Core.Exception
sb.AppendLine(")");
}
var process = System.Diagnostics.Process.GetCurrentProcess();
sb.AppendLine();
sb.AppendLine("## Modules - " + process.ProcessName);
sb.AppendLine();
foreach (ProcessModule mod in process.Modules)
{
sb.Append("* ");
sb.Append(mod.FileName);
sb.Append(" (");
sb.Append(mod.FileVersionInfo.FileDescription);
sb.Append(", ");
sb.Append(mod.FileVersionInfo.FileVersion);
sb.Append(", ");
sb.Append(mod.FileVersionInfo.ProductName);
sb.Append(", ");
sb.Append(mod.FileVersionInfo.ProductVersion);
sb.Append(", ");
sb.Append(mod.FileVersionInfo.CompanyName);
sb.Append("), ");
sb.Append(string.Format("0x{0:X16}", mod.BaseAddress.ToInt64()));
sb.AppendLine();
}
sb.AppendLine();
sb.AppendLine("## Threads - " + process.Threads.Count);
sb.AppendLine();
foreach (ProcessThread th in process.Threads)
{
sb.Append("* ");
sb.AppendLine(string.Format("{0}, {1} {2}, Started: {3}, StartAddress: 0x{4:X16}", th.Id, th.ThreadState, th.PriorityLevel, th.StartTime, th.StartAddress.ToInt64()));
}
return sb.ToString();
}

View File

@@ -10,5 +10,11 @@
{
}
public WoxException(string msg, System.Exception innerException)
: base(msg, innerException)
{
}
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Wox.Core.Exception
{
public class WoxPluginException : WoxException
{
public string PluginName { get; set; }
public WoxPluginException(string pluginName,System.Exception e)
: base(e.Message,e)
{
PluginName = pluginName;
}
}
}

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Wox.Core.Exception;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
//using Wox.Plugin.SystemPlugins;
@@ -28,10 +30,17 @@ namespace Wox.Core.Plugin.QueryDispatcher
PluginPair pair1 = pair;
ThreadPool.QueueUserWorkItem(state =>
{
List<Result> results = pair1.Plugin.Query(query);
results.ForEach(o => { o.AutoAjustScore = true; });
try
{
List<Result> results = pair1.Plugin.Query(query);
results.ForEach(o => { o.AutoAjustScore = true; });
PluginManager.API.PushResults(query, pair1.Metadata, results);
PluginManager.API.PushResults(query, pair1.Metadata, results);
}
catch (System.Exception e)
{
throw new WoxPluginException(pair1.Metadata.Name,e);
}
});
}
}

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Wox.Core.Exception;
using Wox.Core.UserSettings;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
@@ -30,15 +31,9 @@ namespace Wox.Core.Plugin.QueryDispatcher
List<Result> results = userPlugin.Plugin.Query(query) ?? new List<Result>();
PluginManager.API.PushResults(query,userPlugin.Metadata,results);
}
catch (System.Exception queryException)
catch (System.Exception e)
{
Log.Error(string.Format("Plugin {0} query failed: {1}", userPlugin.Metadata.Name,
queryException.Message));
#if (DEBUG)
{
throw;
}
#endif
throw new WoxPluginException(userPlugin.Metadata.Name, e);
}
});
}

View File

@@ -64,6 +64,7 @@
<Compile Include="Exception\WoxHttpException.cs" />
<Compile Include="Exception\WoxI18nException.cs" />
<Compile Include="Exception\WoxJsonRPCException.cs" />
<Compile Include="Exception\WoxPluginException.cs" />
<Compile Include="UserSettings\HttpProxy.cs" />
<Compile Include="i18n\AvailableLanguages.cs" />
<Compile Include="i18n\IInternationalization.cs" />