mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 10:16:24 +02:00
[NetAnalyzers]CA1031 suppressions cleanup (#18706)
This commit is contained in:
committed by
GitHub
parent
33072c7ee3
commit
b33bc2ecd0
@@ -59,9 +59,7 @@ namespace ColorPicker.Mouse
|
||||
Logger.LogInfo("Cursor file path was null");
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Logger.LogError("Failed to change cursor", ex);
|
||||
}
|
||||
|
||||
@@ -28,9 +28,7 @@ namespace ColorPicker
|
||||
application.Run();
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Logger.LogError("Unhandled exception", ex);
|
||||
CursorManager.RestoreOriginalCursors();
|
||||
|
||||
@@ -145,9 +145,7 @@ namespace ColorPicker.Settings
|
||||
Logger.LogError("Failed to read changed settings", ex);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
if (retryCount > MaxNumberOfRetry)
|
||||
{
|
||||
|
||||
@@ -441,11 +441,9 @@ namespace Microsoft.ColorPicker.UnitTests
|
||||
{
|
||||
_ = ColorHelper.ConvertToCMYKColor(color);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
// intentionally trying to catch
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
exception = ex;
|
||||
}
|
||||
|
||||
@@ -57,9 +57,7 @@ namespace ImageResizer
|
||||
Directory.Delete(_path, recursive: true);
|
||||
break;
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Thread.Sleep(150);
|
||||
}
|
||||
|
||||
@@ -75,9 +75,7 @@ namespace ImageResizer.Extensions
|
||||
metadata.RemoveQuery(query);
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Debug.WriteLine($"Exception while trying to remove metadata entry at position: {query}");
|
||||
Debug.WriteLine(ex);
|
||||
@@ -95,9 +93,7 @@ namespace ImageResizer.Extensions
|
||||
{
|
||||
metadata.SetQuery(query, value);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Debug.WriteLine($"Exception while trying to set metadata {value} at position: {query}");
|
||||
Debug.WriteLine(ex);
|
||||
@@ -123,9 +119,7 @@ namespace ImageResizer.Extensions
|
||||
{
|
||||
GetMetadataRecursively(metadata, string.Empty);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Debug.WriteLine($"Exception while trying to iterate recursively over metadata. We were able to read {listOfAllMetadata.Count} metadata entries.");
|
||||
Debug.WriteLine(ex);
|
||||
@@ -145,9 +139,7 @@ namespace ImageResizer.Extensions
|
||||
{
|
||||
metadataQueryReader = GetQueryWithPreCheck(metadata, relativeQuery);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Debug.WriteLine($"Removing corrupt metadata property {absolutePath}. Skipping metadata entry | {ex.Message}");
|
||||
Debug.WriteLine(ex);
|
||||
@@ -223,9 +215,7 @@ namespace ImageResizer.Extensions
|
||||
{
|
||||
GetMetadataRecursively(metadata, string.Empty);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Debug.WriteLine($"Exception while trying to iterate recursively over metadata. We were able to read {listOfAllMetadata.Count} metadata entries.");
|
||||
Debug.WriteLine(ex);
|
||||
@@ -251,9 +241,7 @@ namespace ImageResizer.Extensions
|
||||
metadataQueryReader = metadata.GetQuerySafe(relativeQuery);
|
||||
listOfAllMetadata.Add((absolutePath, metadataQueryReader));
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
listOfAllMetadata.Add((absolutePath, $"######## INVALID METADATA: {ex.Message}"));
|
||||
Debug.WriteLine(ex);
|
||||
|
||||
@@ -70,9 +70,7 @@ namespace ImageResizer.Models
|
||||
{
|
||||
Execute(file);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
errors.Add(new ResizeError { File = _fileSystem.Path.GetFileName(file), Error = ex.Message });
|
||||
}
|
||||
|
||||
@@ -258,9 +258,7 @@ namespace ImageResizer.Models
|
||||
|
||||
return true;
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ namespace Microsoft.Plugin.Folder
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception")]
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
@@ -98,7 +97,6 @@ namespace Microsoft.Plugin.Folder
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception")]
|
||||
private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace Microsoft.Plugin.Indexer
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log and show an error message")]
|
||||
public List<ContextMenuResult> LoadContextMenus(Result selectedResult)
|
||||
{
|
||||
var contextMenus = new List<ContextMenuResult>();
|
||||
@@ -119,7 +118,6 @@ namespace Microsoft.Plugin.Indexer
|
||||
}
|
||||
|
||||
// Function to add the context menu item to run as admin
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception message")]
|
||||
private static ContextMenuResult CreateRunAsAdminContextMenu(SearchResult record)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
@@ -147,7 +145,6 @@ namespace Microsoft.Plugin.Indexer
|
||||
}
|
||||
|
||||
// Function to add the context menu item to run as admin
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log the exception message")]
|
||||
private static ContextMenuResult CreateRunAsUserContextMenu(SearchResult record)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
@@ -190,7 +187,6 @@ namespace Microsoft.Plugin.Indexer
|
||||
return false;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive, and instead log and show an error message")]
|
||||
private ContextMenuResult CreateOpenContainingFolderResult(SearchResult record)
|
||||
{
|
||||
return new ContextMenuResult
|
||||
|
||||
@@ -71,7 +71,6 @@ namespace Microsoft.Plugin.Indexer
|
||||
}
|
||||
|
||||
// This function uses the Windows indexer and returns the list of results obtained
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive but will log the exception")]
|
||||
public List<Result> Query(Query query, bool isFullQuery)
|
||||
{
|
||||
var results = new List<Result>();
|
||||
|
||||
@@ -168,7 +168,6 @@ namespace Microsoft.Plugin.Program
|
||||
return menuOptions;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive and show the user a warning message")]
|
||||
public static void StartProcess(Func<ProcessStartInfo, Process> runProcess, ProcessStartInfo info)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
: Enumerable.Empty<IPackage>();
|
||||
}
|
||||
|
||||
[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.")]
|
||||
private static PackageWrapper TryGetWrapperFromPackage(Package package)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -132,7 +132,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
public bool HasArguments { get; set; }
|
||||
|
||||
// Retrieve the target path using Shell Link
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "HRESULT E_FAIL is thrown while fetching description and E_FAIL does not relate to any specific exception.")]
|
||||
public string RetrieveTargetPath(string path)
|
||||
{
|
||||
var link = new ShellLink();
|
||||
|
||||
@@ -127,7 +127,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
Version = PackageVersion.Unknown;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive.")]
|
||||
public static UWPApplication[] All()
|
||||
{
|
||||
var windows10 = new Version(10, 0);
|
||||
@@ -164,7 +163,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive.")]
|
||||
private static IEnumerable<IPackage> CurrentUserPackages()
|
||||
{
|
||||
return PackageManagerWrapper.FindPackagesForCurrentUser().Where(p =>
|
||||
|
||||
@@ -125,7 +125,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return result;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive.")]
|
||||
public List<ContextMenuResult> ContextMenus(string queryArguments, IPublicAPI api)
|
||||
{
|
||||
if (api == null)
|
||||
@@ -205,7 +204,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return contextMenus;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive, and showing the user an error message")]
|
||||
private async void Launch(IPublicAPI api, string queryArguments)
|
||||
{
|
||||
var appManager = new ApplicationActivationHelper.ApplicationActivationManager();
|
||||
@@ -288,9 +286,7 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
ProgramLogger.Exception($"Unable to parse manifest file for {DisplayName}", e, MethodBase.GetCurrentMethod().DeclaringType, manifest);
|
||||
}
|
||||
|
||||
@@ -247,7 +247,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return result;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive.")]
|
||||
public List<ContextMenuResult> ContextMenus(string queryArguments, IPublicAPI api)
|
||||
{
|
||||
if (api == null)
|
||||
@@ -361,8 +360,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return ExecutableName;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Any error in CreateWin32Program should not prevent other programs from loading.")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "User facing path needs to be shown in lowercase.")]
|
||||
private static Win32Program CreateWin32Program(string path)
|
||||
{
|
||||
try
|
||||
@@ -400,8 +397,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
private static readonly Regex InternetShortcutURLPrefixes = new Regex(@"^steam:\/\/(rungameid|run)\/|^com\.epicgames\.launcher:\/\/apps\/", RegexOptions.Compiled);
|
||||
|
||||
// This function filters Internet Shortcut programs
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Any error in InternetShortcutProgram should not prevent other programs from loading.")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "User facing path needs to be shown in lowercase.")]
|
||||
private static Win32Program InternetShortcutProgram(string path)
|
||||
{
|
||||
try
|
||||
@@ -481,8 +476,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Unsure of what exceptions are caught here while enabling static analysis")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1308:Normalize strings to uppercase", Justification = "User facing path needs to be shown in lowercase.")]
|
||||
private static Win32Program LnkProgram(string path)
|
||||
{
|
||||
try
|
||||
@@ -544,7 +537,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Any error in ExeProgram should not prevent other programs from loading.")]
|
||||
private static Win32Program ExeProgram(string path)
|
||||
{
|
||||
try
|
||||
@@ -652,7 +644,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
: null;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Minimise the effect of error on other programs")]
|
||||
private static IEnumerable<string> ProgramPaths(string directory, IList<string> suffixes, bool recursiveSearch = true)
|
||||
{
|
||||
if (!Directory.Exists(directory))
|
||||
@@ -925,7 +916,6 @@ namespace Microsoft.Plugin.Program.Programs
|
||||
return program;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Keeping the process alive but logging the exception")]
|
||||
public static IList<Win32Program> All(ProgramPluginSettings settings)
|
||||
{
|
||||
if (settings == null)
|
||||
|
||||
@@ -44,9 +44,7 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
{
|
||||
Directory.GetFiles(path);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"Failed to get files in {path}", ex, typeof(Win32ProgramFileSystemWatchers));
|
||||
invalidPaths.Add(path);
|
||||
|
||||
@@ -92,7 +92,6 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive>")]
|
||||
private void OnAppRenamed(object sender, RenamedEventArgs e)
|
||||
{
|
||||
string oldPath = e.OldFullPath;
|
||||
@@ -142,7 +141,6 @@ namespace Microsoft.Plugin.Program.Storage
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Intentionally keeping the process alive")]
|
||||
private void OnAppDeleted(object sender, FileSystemEventArgs e)
|
||||
{
|
||||
string path = e.FullPath;
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace Microsoft.Plugin.Shell
|
||||
_storage.Save();
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Keeping the process alive, but logging the exception")]
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
if (query == null)
|
||||
|
||||
@@ -102,9 +102,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
|
||||
// Result to big to convert to decimal
|
||||
return ErrorHandler.OnError(IconPath, isGlobalQuery, query.RawQuery, Properties.Resources.wox_plugin_calculator_not_covert_to_decimal);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
// Any other crash occurred
|
||||
// We want to keep the process alive if any the mages library throws any exceptions.
|
||||
|
||||
@@ -86,8 +86,6 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
return list;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
/// <summary>
|
||||
/// Open the Windows registry editor and jump to registry key inside the given key (inside the <see cref="RegistryEntry"/>
|
||||
/// </summary>
|
||||
@@ -135,7 +133,5 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ using Microsoft.Win32;
|
||||
|
||||
namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
{
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to easier work with the registry
|
||||
/// </summary>
|
||||
@@ -230,6 +228,4 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
/// </summary>
|
||||
internal static class ResultHelper
|
||||
{
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
/// <summary>
|
||||
/// Return a list with <see cref="Result"/>s, based on the given list
|
||||
/// </summary>
|
||||
@@ -168,8 +166,6 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
|
||||
return resultList;
|
||||
}
|
||||
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
|
||||
/// <summary>
|
||||
/// Return a truncated name
|
||||
/// </summary>
|
||||
|
||||
@@ -6,8 +6,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media.Animation;
|
||||
using Microsoft.PowerToys.Run.Plugin.TimeZone.Classes;
|
||||
using Microsoft.PowerToys.Run.Plugin.TimeZone.Properties;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
@@ -50,8 +48,6 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
|
||||
return list;
|
||||
}
|
||||
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
|
||||
/// <summary>
|
||||
/// Copy the given text to the clipboard
|
||||
/// </summary>
|
||||
@@ -71,7 +67,5 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeZone.Helper
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,9 +137,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
|
||||
{
|
||||
appManager.ActivateApplication(id, queryArguments, noFlags, out var unusedPid);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
var name = "Plugin: " + Resources.plugin_name;
|
||||
var message = Resources.run_terminal_failed;
|
||||
@@ -155,9 +153,7 @@ namespace Microsoft.PowerToys.Run.Plugin.WindowsTerminal
|
||||
string path = "shell:AppsFolder\\" + id;
|
||||
Helper.OpenInShell(path, TerminalHelper.GetArguments(profile, _openNewTab), runAs: Helper.ShellRunAsType.Administrator);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
var name = "Plugin: " + Resources.plugin_name;
|
||||
var message = Resources.run_terminal_failed;
|
||||
|
||||
@@ -139,9 +139,7 @@ namespace PowerLauncher.Helper
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
// The dotnet method "System.Environment.SetEnvironmentVariable" has it's own internal method to check the input parameters. Here we catch the exceptions that we don't check before updating the environment variable and log it to avoid crashes of PT Run.
|
||||
Log.Exception($"Unhandled exception while updating the environment variable [{kv.Key}] for the PT Run process. (The variable value has a length of [{varValueLength}].)", ex, typeof(PowerLauncher.Helper.EnvironmentHelper));
|
||||
@@ -215,9 +213,7 @@ namespace PowerLauncher.Helper
|
||||
{
|
||||
return Environment.GetEnvironmentVariables(target);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"Unhandled exception while getting the environment variables for target '{target}'.", ex, typeof(PowerLauncher.Helper.EnvironmentHelper));
|
||||
return new Hashtable();
|
||||
|
||||
@@ -68,9 +68,7 @@ namespace PowerLauncher
|
||||
var telemetryEvent = new RunPluginsSettingsEvent(plugins);
|
||||
PowerToysTelemetry.Log.WriteEvent(telemetryEvent);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception("Unhandled exception when trying to send PowerToys Run settings telemetry.", ex, GetType());
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ namespace PowerLauncher.Plugin
|
||||
return PluginMetadatas;
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
private static void ParsePluginConfigs(IEnumerable<string> directories)
|
||||
{
|
||||
// todo use linq when diable plugin is implemented since parallel.foreach + list is not thread saft
|
||||
@@ -65,7 +64,6 @@ namespace PowerLauncher.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
private static PluginMetadata GetPluginMetadata(string pluginDirectory)
|
||||
{
|
||||
string configPath = Path.Combine(pluginDirectory, PluginConfigName);
|
||||
|
||||
@@ -12,7 +12,6 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using PowerLauncher.Properties;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
using Wox.Plugin.Logger;
|
||||
@@ -135,7 +134,6 @@ namespace PowerLauncher.Plugin
|
||||
/// <summary>
|
||||
/// Call initialize for all plugins
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
public static void InitializePlugins(IPublicAPI api)
|
||||
{
|
||||
API = api ?? throw new ArgumentNullException(nameof(api));
|
||||
@@ -165,7 +163,6 @@ namespace PowerLauncher.Plugin
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
public static List<Result> QueryForPlugin(PluginPair pair, Query query, bool delayedExecution = false)
|
||||
{
|
||||
if (pair == null)
|
||||
@@ -272,7 +269,6 @@ namespace PowerLauncher.Plugin
|
||||
return AllPlugins.Where(p => p.Plugin is T);
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
public static List<ContextMenuResult> GetContextMenusForPlugin(Result result)
|
||||
{
|
||||
var pluginPair = _contextMenuPlugins.FirstOrDefault(o => o.Metadata.ID == result.PluginID);
|
||||
|
||||
@@ -780,9 +780,7 @@ namespace PowerLauncher.ViewModel
|
||||
_hotkeyHandle = HotkeyManager.RegisterHotkey(hotkey, action);
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
string errorMsg = string.Format(CultureInfo.InvariantCulture, Properties.Resources.registerHotkeyFailed, hotkeyStr);
|
||||
MessageBox.Show(errorMsg);
|
||||
|
||||
@@ -193,9 +193,7 @@ namespace PowerLauncher.ViewModel
|
||||
{
|
||||
return Result.Icon();
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"IcoPath is empty and exception when calling Icon() for result <{Result.Title}> of plugin <{Result.PluginDirectory}>", e, GetType());
|
||||
imagePath = ImageLoader.ErrorIconPath;
|
||||
|
||||
@@ -117,7 +117,6 @@ namespace Wox.Infrastructure.Exception
|
||||
}
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
private static List<string> GetFrameworkVersionFromRegistry()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -94,7 +94,6 @@ namespace Wox.Infrastructure
|
||||
}
|
||||
|
||||
// Function to run as admin for context menu items
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
public static void RunAsAdmin(string path)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
@@ -116,7 +115,6 @@ namespace Wox.Infrastructure
|
||||
}
|
||||
|
||||
// Function to run as other user for context menu items
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
public static void RunAsUser(string path)
|
||||
{
|
||||
var info = new ProcessStartInfo
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace Wox.Infrastructure.Image
|
||||
{
|
||||
public class ImageHashGenerator : IImageHashGenerator
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350:Do Not Use Weak Cryptographic Algorithms", Justification = "Level of protection needed for the image data does not require a security guarantee")]
|
||||
public string GetHashFromImage(ImageSource image)
|
||||
{
|
||||
|
||||
@@ -119,7 +119,6 @@ namespace Wox.Infrastructure.Image
|
||||
Cache,
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
private static ImageResult LoadInternal(string path, bool loadFullImage = false)
|
||||
{
|
||||
ImageSource image;
|
||||
|
||||
@@ -86,7 +86,6 @@ namespace Wox.Infrastructure.Storage
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Suppressing this to enable FxCop. We are logging the exception, and going forward general exceptions should not be caught")]
|
||||
private T Deserialize(Stream stream, T defaultData)
|
||||
{
|
||||
// http://stackoverflow.com/questions/2120055/binaryformatter-deserialize-gives-serializationexception
|
||||
|
||||
@@ -61,7 +61,6 @@ namespace Wox.Plugin.Common
|
||||
/// Consider using <see cref="UpdateIfTimePassed"/> to avoid updating multiple times.
|
||||
/// (because of multiple plugins calling update at the same time.)
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive but will log the exception")]
|
||||
public static void Update()
|
||||
{
|
||||
lock (_updateLock)
|
||||
|
||||
@@ -136,9 +136,7 @@ namespace Wox.Plugin
|
||||
{
|
||||
_assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(Metadata.ExecuteFilePath);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"Couldn't load assembly for {Metadata.Name} in {Metadata.ExecuteFilePath}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
return false;
|
||||
@@ -170,9 +168,7 @@ namespace Wox.Plugin
|
||||
{
|
||||
Plugin = (IPlugin)Activator.CreateInstance(type);
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"Can't create instance for <{Metadata.Name}> in {Metadata.ExecuteFilePath}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
return false;
|
||||
@@ -197,9 +193,7 @@ namespace Wox.Plugin
|
||||
API = api,
|
||||
});
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
Log.Exception($"Fail to Init plugin: {Metadata.Name}", e, GetType());
|
||||
return false;
|
||||
|
||||
@@ -75,9 +75,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Gcode
|
||||
base.DoPreview(dataSource);
|
||||
PowerToysTelemetry.Log.WriteEvent(new GcodeFilePreviewed());
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
PreviewError(ex, dataSource);
|
||||
}
|
||||
|
||||
@@ -130,9 +130,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
});
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Password protected files throws an generic Exception
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
if (ex.Message.Contains("Unable to update the password. The value provided as the current password is incorrect.", StringComparison.Ordinal))
|
||||
{
|
||||
@@ -156,9 +154,7 @@ namespace Microsoft.PowerToys.PreviewHandler.Pdf
|
||||
|
||||
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewed());
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
PowerToysTelemetry.Log.WriteEvent(new PdfFilePreviewError { Message = ex.Message });
|
||||
|
||||
|
||||
@@ -59,9 +59,7 @@ namespace Common.Utilities
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning disable CA1031 // Do not catch general exception types
|
||||
catch (Exception)
|
||||
#pragma warning restore CA1031 // Do not catch general exception types
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user