mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
handle error in Packaged program loading (#6674)
This commit is contained in:
committed by
GitHub
parent
b3833fcf1a
commit
00187269de
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user