Skip to content
Merged
14 changes: 12 additions & 2 deletions src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
// 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.Diagnostics;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Programs;
using Microsoft.CmdPal.Ext.Apps.Properties;
using Microsoft.CommandPalette.Extensions.Toolkit;
Expand Down Expand Up @@ -33,8 +35,9 @@ await Task.Run(() =>
{
appManager.ActivateApplication(aumid, /*queryArguments*/ string.Empty, noFlags, out var unusedPid);
}
catch (System.Exception)
catch (System.Exception ex)
{
Logger.LogError(ex.Message);
}
}).ConfigureAwait(false);
}
Expand All @@ -46,7 +49,14 @@ internal static async Task StartExe(string path)
// const ActivateOptions noFlags = ActivateOptions.None;
await Task.Run(() =>
{
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
try
{
Process.Start(new ProcessStartInfo(path) { UseShellExecute = true });
}
catch (System.Exception ex)
{
Logger.LogError(ex.Message);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,9 +39,9 @@ await Task.Run(() =>

Process.Start(processStartInfo);
}
catch (Exception)
catch (Exception ex)
{
// Log.Exception($"Failed to open {Name} in console, {e.Message}", e, GetType());
Logger.LogError(ex.Message);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.IO;
using ManagedCommon;
using Windows.Foundation.Metadata;
using Package = Windows.ApplicationModel.Package;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
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;
Expand Down Expand Up @@ -131,8 +133,9 @@ public static UWPApplication[] All()
u = new UWP(p);
u.InitializeAppInfo(p.InstalledLocation);
}
catch (Exception )
catch (Exception ex)
{
Logger.LogError(ex.Message);
return Array.Empty<UWPApplication>();
}

Expand Down Expand Up @@ -161,8 +164,9 @@ private static IEnumerable<IPackage> CurrentUserPackages()
var path = p.InstalledLocation;
return !f && !string.IsNullOrEmpty(path);
}
catch (Exception )
catch (Exception ex)
{
Logger.LogError(ex.Message);
return false;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
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;

Expand Down Expand Up @@ -154,8 +156,9 @@ private bool IfApplicationCanRunElevated()
return true;
}
}
catch (Exception)
catch (Exception ex)
{
Logger.LogError(ex.Message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -239,10 +240,12 @@ private static Win32Program CreateWin32Program(string path)
}
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;
}
}
Expand Down Expand Up @@ -317,11 +320,13 @@ private static Win32Program InternetShortcutProgram(string path)
}
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;
}
}
Expand Down Expand Up @@ -374,15 +379,17 @@ private static Win32Program LnkProgram(string path)

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;
}
}
Expand All @@ -402,14 +409,17 @@ private static Win32Program ExeProgram(string path)
}
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;
}
}
Expand Down Expand Up @@ -515,16 +525,19 @@ private static IEnumerable<string> ProgramPaths(string directory, IList<string>
{
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
Expand All @@ -548,9 +561,11 @@ private static IEnumerable<string> ProgramPaths(string directory, IList<string>
}
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);
Expand Down Expand Up @@ -682,6 +697,7 @@ private static string GetPathFromRegistrySubkey(RegistryKey root, string subkey)
}
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException)
{
Logger.LogError(e.Message);
return string.Empty;
}
}
Expand Down Expand Up @@ -769,8 +785,9 @@ private static bool TryGetIcoPathForRunCommandProgram(Win32Program program, out
icoPath = ExpandEnvironmentVariables(redirectionPath);
return true;
}
catch (IOException)
catch (IOException e)
{
Logger.LogError(e.Message);
}

icoPath = null;
Expand Down Expand Up @@ -839,8 +856,9 @@ public static IList<Win32Program> All(AllAppsSettings settings)

return DeduplicatePrograms(programs.Concat(runCommandPrograms).Where(program => program?.Valid == true));
}
catch (Exception)
catch (Exception e)
{
Logger.LogError(e.Message);
return Array.Empty<Win32Program>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using ManagedCommon;

namespace Microsoft.CmdPal.Ext.Apps.Storage;

Expand Down Expand Up @@ -37,8 +38,9 @@ public void SetList(IList<T> list)
_items = new ConcurrentDictionary<int, T>(list.ToDictionary(i => i.GetHashCode()));
#pragma warning restore CS8602 // Dereference of a possibly null reference.
}
catch (ArgumentException)
catch (ArgumentException ex)
{
Logger.LogInfo(ex.Message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,8 +93,9 @@ private void AddPackage(Package package)
// 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ManagedCommon;

namespace Microsoft.CmdPal.Ext.Apps.Storage;

Expand Down Expand Up @@ -47,8 +48,9 @@ private static string[] GetPathsToWatch()
{
Directory.GetFiles(path);
}
catch (Exception)
catch (Exception e)
{
Logger.LogError(e.Message);
invalidPaths.Add(path);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;

Expand Down Expand Up @@ -132,8 +133,9 @@ private async Task OnAppRenamedAsync(object sender, RenamedEventArgs e)
oldApp = Win32Program.GetAppFromPath(oldPath);
}
}
catch (Exception)
catch (Exception ex)
{
Logger.LogError(ex.Message);
}

// To remove the old app which has been renamed and to add the new application.
Expand Down Expand Up @@ -192,8 +194,9 @@ private void OnAppDeleted(object sender, FileSystemEventArgs e)
app = Programs.Win32Program.GetAppFromPath(path);
}
}
catch (Exception)
catch (Exception ex)
{
Logger.LogError(ex.Message);
}

if (app != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using ManagedCommon;

namespace Microsoft.CmdPal.Ext.Apps.Utils;

Expand Down Expand Up @@ -138,9 +139,9 @@ public string RetrieveTargetPath(string path)
{
((IPersistFile)link).Load(path, STGM_READ);
}
catch (System.IO.FileNotFoundException)
catch (System.IO.FileNotFoundException ex)
{
// Log.Exception("Path could not be retrieved", ex, GetType(), path);
Logger.LogError(ex.Message);
return string.Empty;
}

Expand All @@ -163,9 +164,9 @@ public string RetrieveTargetPath(string path)
((IShellLinkW)link).GetDescription(buffer, MAX_PATH);
Description = buffer.ToString();
}
catch (Exception)
catch (Exception ex)
{
// Log.Exception($"Failed to fetch description for {target}, {e.Message}", e, GetType());
Logger.LogError(ex.Message);
Description = string.Empty;
}

Expand Down
Loading
Loading