handle error in Packaged program loading (#6674)

This commit is contained in:
Divyansh Srivastava
2020-09-17 16:17:02 -07:00
committed by GitHub
parent b3833fcf1a
commit 00187269de
2 changed files with 13 additions and 3 deletions

View File

@@ -49,9 +49,9 @@ namespace Microsoft.Plugin.Program.Programs
{
path = package.InstalledLocation.Path;
}
catch (Exception e) when (e is ArgumentException || e is FileNotFoundException)
catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException)
{
ProgramLogger.LogException($"PackageWrapper", "GetWrapperFromPackage", "package.InstalledLocation.Path", $"Exception {package.Id.Name}", e);
ProgramLogger.LogException($"PackageWrapper", "GetWrapperFromPackage", "Path could not be determined", $"Exception {package.Id.Name}", e);
return new PackageWrapper(
package.Id.Name,
package.Id.FullName,

View File

@@ -2,9 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Security.Principal;
using Windows.Management.Deployment;
using Wox.Infrastructure.Logger;
using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs
@@ -18,6 +20,7 @@ namespace Microsoft.Plugin.Program.Programs
_packageManager = new PackageManager();
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to catch all exception to prevent error in a program from affecting loading of program plugin.")]
public IEnumerable<IPackage> FindPackagesForCurrentUser()
{
List<PackageWrapper> packages = new List<PackageWrapper>();
@@ -28,9 +31,16 @@ namespace Microsoft.Plugin.Program.Programs
var id = user.Value;
var m = _packageManager.FindPackagesForUser(id);
foreach (Package p in m)
{
try
{
packages.Add(PackageWrapper.GetWrapperFromPackage(p));
}
catch (Exception e)
{
Log.Error(nameof(PackageManagerWrapper), e.Message, nameof(FindPackagesForCurrentUser));
}
}
}
return packages;