diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCommand.cs index 682c79bdb8..6cb416f271 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCommand.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Threading.Tasks; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Programs; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -33,8 +34,9 @@ internal sealed partial class AppCommand : InvokableCommand { appManager.ActivateApplication(aumid, /*queryArguments*/ string.Empty, noFlags, out var unusedPid); } - catch (System.Exception) + catch (System.Exception ex) { + Logger.LogError(ex.Message); } }).ConfigureAwait(false); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs index 57c9175d4d..d67f9beed8 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using ManagedCommon; using Microsoft.CommandPalette.Extensions; using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.Storage.Streams; @@ -73,10 +74,11 @@ internal sealed partial class AppListItem : ListItem heroImage = IconInfo.FromStream(stream); } } - catch (Exception) + catch (Exception ex) { + Logger.LogError(ex.Message); + // do nothing if we fail to load an icon. - // Logging it would be too NOISY, there's really no need. } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs index de68cafeb8..41e934759a 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/OpenInConsoleCommand.cs @@ -5,6 +5,7 @@ using System; using System.Diagnostics; using System.Threading.Tasks; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CommandPalette.Extensions.Toolkit; @@ -38,9 +39,9 @@ internal sealed partial class OpenInConsoleCommand : InvokableCommand Process.Start(processStartInfo); } - catch (Exception) + catch (Exception ex) { - // Log.Exception($"Failed to open {Name} in console, {e.Message}", e, GetType()); + Logger.LogError(ex.Message); } }); } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/PackageWrapper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/PackageWrapper.cs index 2de128c05c..00f33d1efd 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/PackageWrapper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/PackageWrapper.cs @@ -4,6 +4,7 @@ using System; using System.IO; +using ManagedCommon; using Windows.Foundation.Metadata; using Package = Windows.ApplicationModel.Package; @@ -51,6 +52,7 @@ public class PackageWrapper : IPackage } catch (Exception e) when (e is ArgumentException || e is FileNotFoundException || e is DirectoryNotFoundException) { + Logger.LogError(e.Message); return new PackageWrapper( package.Id.Name, package.Id.FullName, 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 beba2b185a..e115911001 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 @@ -7,7 +7,9 @@ using System.Collections.Generic; using System.IO.Abstractions; using System.Linq; using System.Xml.Linq; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Utils; +using Microsoft.CommandPalette.Extensions.Toolkit; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.System.Com; @@ -131,8 +133,9 @@ public partial class UWP u = new UWP(p); u.InitializeAppInfo(p.InstalledLocation); } - catch (Exception ) + catch (Exception ex) { + Logger.LogError(ex.Message); return Array.Empty(); } @@ -161,8 +164,9 @@ public partial class UWP var path = p.InstalledLocation; return !f && !string.IsNullOrEmpty(path); } - catch (Exception ) + catch (Exception ex) { + Logger.LogError(ex.Message); return false; } }); diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs index 7a35400a7a..c38c05d7b5 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/UWPApplication.cs @@ -8,12 +8,14 @@ using System.IO.Abstractions; using System.Linq; using System.Text; using System.Xml; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; using Microsoft.CommandPalette.Extensions.Toolkit; using static Microsoft.CmdPal.Ext.Apps.Utils.Native; using PackageVersion = Microsoft.CmdPal.Ext.Apps.Programs.UWP.PackageVersion; +using Theme = Microsoft.CmdPal.Ext.Apps.Utils.Theme; namespace Microsoft.CmdPal.Ext.Apps.Programs; @@ -154,8 +156,9 @@ public class UWPApplication : IProgram return true; } } - catch (Exception) + catch (Exception ex) { + Logger.LogError(ex.Message); } } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs index 48dfaa2f7e..11c9be6be5 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Programs/Win32Program.cs @@ -15,6 +15,7 @@ using System.Security; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Input; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Commands; using Microsoft.CmdPal.Ext.Apps.Properties; using Microsoft.CmdPal.Ext.Apps.Utils; @@ -239,10 +240,12 @@ public class Win32Program : IProgram } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); return InvalidProgram; } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); return InvalidProgram; } } @@ -317,11 +320,13 @@ public class Win32Program : IProgram } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); return InvalidProgram; } } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); return InvalidProgram; } } @@ -374,15 +379,17 @@ public class Win32Program : IProgram return program; } - catch (System.IO.FileLoadException) + catch (System.IO.FileLoadException e) { + Logger.LogError(e.Message); return InvalidProgram; } // Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in. // Error caused likely due to trying to get the description of the program - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); return InvalidProgram; } } @@ -402,14 +409,17 @@ public class Win32Program : IProgram } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); return InvalidProgram; } - catch (FileNotFoundException) + catch (FileNotFoundException e) { + Logger.LogError(e.Message); return InvalidProgram; } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); return InvalidProgram; } } @@ -515,16 +525,19 @@ public class Win32Program : IProgram { files.AddRange(Directory.EnumerateFiles(currentDirectory, $"*.{suffix}", SearchOption.TopDirectoryOnly)); } - catch (DirectoryNotFoundException) + catch (DirectoryNotFoundException e) { + Logger.LogError(e.Message); } } } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); } try @@ -548,9 +561,11 @@ public class Win32Program : IProgram } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); } } while (folderQueue.Count > 0); @@ -682,6 +697,7 @@ public class Win32Program : IProgram } catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) { + Logger.LogError(e.Message); return string.Empty; } } @@ -769,8 +785,9 @@ public class Win32Program : IProgram icoPath = ExpandEnvironmentVariables(redirectionPath); return true; } - catch (IOException) + catch (IOException e) { + Logger.LogError(e.Message); } icoPath = null; @@ -839,8 +856,9 @@ public class Win32Program : IProgram return DeduplicatePrograms(programs.Concat(runCommandPrograms).Where(program => program?.Valid == true)); } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); return Array.Empty(); } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/ListRepository`1.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/ListRepository`1.cs index aea8590c58..81d98b0b76 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/ListRepository`1.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/ListRepository`1.cs @@ -7,6 +7,7 @@ using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; +using ManagedCommon; namespace Microsoft.CmdPal.Ext.Apps.Storage; @@ -37,8 +38,9 @@ public class ListRepository : IRepository, IEnumerable _items = new ConcurrentDictionary(list.ToDictionary(i => i.GetHashCode())); #pragma warning restore CS8602 // Dereference of a possibly null reference. } - catch (ArgumentException) + catch (ArgumentException ex) { + Logger.LogError(ex.Message); } } 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 1f7a747d57..566817ea5d 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 @@ -4,8 +4,8 @@ using System; using System.Linq; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Programs; -using Microsoft.CmdPal.Ext.Apps.Storage; using Microsoft.CmdPal.Ext.Apps.Utils; using Windows.ApplicationModel; @@ -93,8 +93,9 @@ internal sealed partial class PackageRepository : ListRepository // InitializeAppInfo will throw if there is no AppxManifest.xml for the package. // Note there are sometimes multiple packages per product and this doesn't necessarily mean that we haven't found the app. // eg. "Could not find file 'C:\\Program Files\\WindowsApps\\Microsoft.WindowsTerminalPreview_2020.616.45.0_neutral_~_8wekyb3d8bbwe\\AppxManifest.xml'." - catch (System.IO.FileNotFoundException) + catch (System.IO.FileNotFoundException ex) { + Logger.LogError(ex.Message); } } diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramFileSystemWatchers.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramFileSystemWatchers.cs index 6847e619e1..3e992cc807 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramFileSystemWatchers.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Storage/Win32ProgramFileSystemWatchers.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using ManagedCommon; namespace Microsoft.CmdPal.Ext.Apps.Storage; @@ -47,8 +48,9 @@ internal sealed partial class Win32ProgramFileSystemWatchers : IDisposable { Directory.GetFiles(path); } - catch (Exception) + catch (Exception e) { + Logger.LogError(e.Message); invalidPaths.Add(path); } } 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 5a0eb09451..9592599b17 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 @@ -9,6 +9,7 @@ using System.Collections.ObjectModel; using System.IO; using System.IO.Abstractions; using System.Threading.Tasks; +using ManagedCommon; using Microsoft.CmdPal.Ext.Apps.Programs; using Win32Program = Microsoft.CmdPal.Ext.Apps.Programs.Win32Program; @@ -132,8 +133,9 @@ internal sealed partial class Win32ProgramRepository : ListRepository +