From 2398b5e6f09d59a8ac4f43e70508fda7c549b565 Mon Sep 17 00:00:00 2001 From: Davide Giacometti <25966642+davidegiacometti@users.noreply.github.com> Date: Sun, 20 Jul 2025 20:43:27 +0200 Subject: [PATCH] [CmdPal][App] Handle app indexing errors (#40717) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary of the Pull Request #40100 OP is hitting an `AggregateException`. This PR aim to improve error handling and logging. It also remove some dead code 😄 ## PR Checklist - [x] **Closes:** #40100 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs | 24 +++++++++++++++++-- .../Microsoft.CmdPal.Ext.Apps/Programs/UWP.cs | 8 ------- .../Storage/PackageRepository.cs | 6 +---- .../Storage/Win32ProgramRepository.cs | 3 +-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs index fcbf7301da..a0c3f7c363 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCache.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; using Microsoft.CmdPal.Ext.Apps.Programs; @@ -46,7 +47,19 @@ public sealed partial class AppCache : IDisposable UpdateUWPIconPath(ThemeHelper.GetCurrentTheme()); }); - Task.WaitAll(a, b); + try + { + Task.WaitAll(a, b); + } + catch (AggregateException ex) + { + ManagedCommon.Logger.LogError("One or more errors occurred while indexing apps"); + + foreach (var inner in ex.InnerExceptions) + { + ManagedCommon.Logger.LogError(inner.Message, inner); + } + } AllAppsSettings.Instance.LastIndexTime = DateTime.Today; } @@ -57,7 +70,14 @@ public sealed partial class AppCache : IDisposable { foreach (UWPApplication app in _packageRepository) { - app.UpdateLogoPath(theme); + try + { + app.UpdateLogoPath(theme); + } + catch (Exception ex) + { + ManagedCommon.Logger.LogError($"Failed to update icon path for app {app.Name}", ex); + } } } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWP.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWP.cs index 15d7c079db..9be6cc9eb2 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWP.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWP.cs @@ -128,14 +128,6 @@ public partial class UWP public static UWPApplication[] All() { - var windows10 = new Version(10, 0); - var support = Environment.OSVersion.Version.Major >= windows10.Major; - - if (!support) - { - return Array.Empty(); - } - var appsBag = new ConcurrentBag(); Parallel.ForEach(CurrentUserPackages(), p => diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/PackageRepository.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/PackageRepository.cs index 3373393080..3a12958f1e 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/PackageRepository.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/PackageRepository.cs @@ -115,11 +115,7 @@ internal sealed partial class PackageRepository : ListRepository public void IndexPrograms() { - var windows10 = new Version(10, 0); - var support = Environment.OSVersion.Version.Major >= windows10.Major; - - var applications = support ? Programs.UWP.All() : Array.Empty(); - + var applications = UWP.All(); SetList(applications); } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramRepository.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramRepository.cs index ab8139b1e2..6fdb5e49f6 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramRepository.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramRepository.cs @@ -267,8 +267,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository