[NetAnalyzers]CA1031 suppressions cleanup (#18706)

This commit is contained in:
Davide Giacometti
2022-06-12 15:11:52 +02:00
committed by GitHub
parent 33072c7ee3
commit b33bc2ecd0
54 changed files with 0 additions and 143 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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>();

View File

@@ -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

View File

@@ -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

View File

@@ -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();

View File

@@ -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 =>

View File

@@ -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);
}

View File

@@ -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)

View File

@@ -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);

View File

@@ -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;

View File

@@ -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)

View File

@@ -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.

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -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>

View File

@@ -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
}
}

View File

@@ -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;