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; 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( return new PackageWrapper(
package.Id.Name, package.Id.Name,
package.Id.FullName, package.Id.FullName,

View File

@@ -2,9 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license. // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Principal; using System.Security.Principal;
using Windows.Management.Deployment; using Windows.Management.Deployment;
using Wox.Infrastructure.Logger;
using Package = Windows.ApplicationModel.Package; using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
@@ -18,6 +20,7 @@ namespace Microsoft.Plugin.Program.Programs
_packageManager = new PackageManager(); _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() public IEnumerable<IPackage> FindPackagesForCurrentUser()
{ {
List<PackageWrapper> packages = new List<PackageWrapper>(); List<PackageWrapper> packages = new List<PackageWrapper>();
@@ -29,7 +32,14 @@ namespace Microsoft.Plugin.Program.Programs
var m = _packageManager.FindPackagesForUser(id); var m = _packageManager.FindPackagesForUser(id);
foreach (Package p in m) foreach (Package p in m)
{ {
packages.Add(PackageWrapper.GetWrapperFromPackage(p)); try
{
packages.Add(PackageWrapper.GetWrapperFromPackage(p));
}
catch (Exception e)
{
Log.Error(nameof(PackageManagerWrapper), e.Message, nameof(FindPackagesForCurrentUser));
}
} }
} }