Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WinGet/Pages/InstallPackageListItem.cs (C#)

Code before:

    private InstallPackageCommand? _installCommand;

    public InstallPackageListItem(CatalogPackage package)
        : base(new NoOpCommand())
    {
        _package = package;

        var version = _package.DefaultInstallVersion ?? _package.InstalledVersion;
        var versionTagText = "Unknown";
        if (version != null)
        {
            versionTagText = version.Version == "Unknown" && version.PackageCatalog.Info.Id == "StoreEdgeFD" ? "msstore" : version.Version;
        }

        Title = _package.Name;
        Subtitle = _package.Id;
        Tags = [new Tag() { Text = versionTagText }];

        _details = new Lazy<Details?>(() => BuildDetails(version));

        _ = Task.Run(() =>
        {
            try
            {
                UpdatedInstalledStatus();
            }
            catch (Exception ex)
            {
                ExtensionHost.LogMessage($"[WinGet] UpdatedInstalledStatus throw exception: {ex.Message}");
            }
        });
    }

    private Details? BuildDetails(PackageVersionInfo? version)
    {
        CatalogPackageMetadata? metadata = null;
        try
        {
            metadata = version?.GetCatalogPackageMetadata();
        }
        catch (COMException ex)
        {
            Logger.LogWarning($"{ex.ErrorCode}");
        }

        if (metadata != null)
        {
            if (metadata.Tags.Where(t => t.Equals(WinGetExtensionPage.ExtensionsTag, StringComparison.OrdinalIgnoreCase)).Any())
            {
                if (_installCommand != null)

Review comment (suggestion):
This one are calling at both event handler and here.
Let's do minimal try catch within UpdatedInstalledStatus just for that "var status = await _package.CheckInstalledStatusAsync();", which will be similar pattern like BuildDetails method now which only handle the com calling exception.

Code after:

    private InstallPackageCommand? _installCommand;

    public InstallPackageListItem(CatalogPackage package)
        : base(new NoOpCommand())
    {
        _package = package;

        var version = _package.DefaultInstallVersion ?? _package.InstalledVersion;
        var versionTagText = "Unknown";
        if (version != null)
        {
            versionTagText = version.Version == "Unknown" && version.PackageCatalog.Info.Id == "StoreEdgeFD" ? "msstore" : version.Version;
        }

        Title = _package.Name;
        Subtitle = _package.Id;
        Tags = [new Tag() { Text = versionTagText }];

        _details = new Lazy<Details?>(() => BuildDetails(version));

        _ = Task.Run(UpdatedInstalledStatus);
    }

    private Details? BuildDetails(PackageVersionInfo? version)
    {
        CatalogPackageMetadata? metadata = null;
        try
        {
            metadata = version?.GetCatalogPackageMetadata();
        }
        catch (COMException ex)
        {
            Logger.LogWarning($"{ex.ErrorCode}");
        }

        if (metadata != null)
        {
            if (metadata.Tags.Where(t => t.Equals(WinGetExtensionPage.ExtensionsTag, StringComparison.OrdinalIgnoreCase)).Any())
            {
                if (_installCommand != null)
                {
                    _installCommand.SkipDependencies = true;
                }
            }

            var description = string.IsNullOrEmpty(metadata.Description) ? metadata.ShortDescription : metadata.Description;
            var detailsBody = $"""

{description}
""";