Skip to content

Commit

Permalink
add extra data to exception
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-qian committed May 14, 2020
1 parent 4468f63 commit d075faa
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
43 changes: 36 additions & 7 deletions Plugins/Wox.Plugin.Program/Programs/UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private void InitializeAppInfo()
else
{
var e = Marshal.GetExceptionForHR((int)hResult);
e.Data.Add(nameof(path), path);
Logger.WoxError($"Cannot not get UWP details {path}", e);
Apps = new List<Application>().ToArray();
return;
Expand Down Expand Up @@ -168,7 +169,8 @@ public static Application[] All()
}
catch (Exception e)
{
Logger.WoxError($"Cannot parse UWP {p.Id.FullName} {p.Id.Version} {p.Id}", e);
e.Data.Add(nameof(p.Id.FullName), p.Id.FullName);
Logger.WoxError($"Cannot parse UWP {p.Id.FullName}", e);
return new Application[] { };
}
return u.Apps;
Expand Down Expand Up @@ -203,7 +205,9 @@ private static IEnumerable<Package> CurrentUserPackages()
}
catch (Exception e)
{
Logger.WoxError($"cannot get package {u} {p.Id}", e);
e.Data.Add(nameof(u), u);
e.Data.Add(nameof(p.Id.FullName), p.Id.FullName);
Logger.WoxError($"cannot get package {u} {p.Id.FullName}", e);
return false;
}
Expand Down Expand Up @@ -397,8 +401,19 @@ internal string ResourcesFromPri(string packageFullName, String packageName, str
}
parsed = $"{prefix}//{packageName}{key}";
}
Logger.WoxDebug($"resourceReference {resourceReference} parsed <{parsed}> package <{packageFullName}>");
result = ResourceFromPriInternal(packageFullName, parsed);
string message = $"resourceReference {resourceReference} parsed <{parsed}> package <{packageFullName}>";
Logger.WoxDebug(message);
try
{
result = ResourceFromPriInternal(packageFullName, parsed);
}
catch (Exception e)
{
e.Data.Add(nameof(resourceReference), resourceReference);
e.Data.Add(nameof(ResourcesFromPri) + nameof(parsed), parsed);
e.Data.Add(nameof(ResourcesFromPri) + nameof(packageFullName), packageFullName);
throw e;
}
}
else
{
Expand All @@ -417,9 +432,19 @@ private string FilesFromPri(string packageFullName, string packageName, string f

Logger.WoxTrace($"package: <{packageFullName}> file ref: <{fileReference}>");
string parsed = $"ms-resource://{packageName}/Files/{fileReference.Replace("\\", "/")}";
string result = ResourceFromPriInternal(packageFullName, parsed);
Logger.WoxTrace($"package: <{packageFullName}> pri file result: <{result}>");
return result;
try
{
string result = ResourceFromPriInternal(packageFullName, parsed);
Logger.WoxTrace($"package: <{packageFullName}> pri file result: <{result}>");
return result;
}
catch (Exception e)
{
e.Data.Add(nameof(fileReference), fileReference);
e.Data.Add(nameof(FilesFromPri) + nameof(parsed), parsed);
e.Data.Add(nameof(FilesFromPri) + nameof(packageFullName), packageFullName);
throw e;
}
}

/// https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-shloadindirectstring
Expand Down Expand Up @@ -451,6 +476,10 @@ private string ResourceFromPriInternal(string packageFullName, string parsed)
else
{
var e = Marshal.GetExceptionForHR((int)hResult);
e.Data.Add(nameof(source), source);
e.Data.Add(nameof(Package.Location), Package.Location);
e.Data.Add(nameof(packageFullName), packageFullName);
e.Data.Add(nameof(parsed), parsed);
Logger.WoxError($"Load pri failed {source} location {Package.Location}", e);
return string.Empty;
}
Expand Down
10 changes: 10 additions & 0 deletions Wox.Infrastructure/Exception/ExceptionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ private static void FormattedSingleException(System.Exception ex, StringBuilder
sb.Append(Indent(indentLevel));
sb.Append("HResult: ");
sb.AppendLine(ex.HResult.ToString());
foreach(object key in ex.Data.Keys)
{
object value = ex.Data[key];
sb.Append(Indent(indentLevel));
sb.Append("Data: <");
sb.Append(key);
sb.Append("> -> <");
sb.Append(value);
sb.AppendLine(">");
}

if (ex.Source != null)
{
Expand Down

0 comments on commit d075faa

Please sign in to comment.