From a55b66aa6f699fee400e8682b370b44048dbd77d Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Thu, 3 Nov 2022 16:21:18 +0000
Subject: [PATCH 1/7] Initial Commit
---
Rules/AvoidGeneralCatch.cs | 110 +++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
create mode 100644 Rules/AvoidGeneralCatch.cs
diff --git a/Rules/AvoidGeneralCatch.cs b/Rules/AvoidGeneralCatch.cs
new file mode 100644
index 000000000..9e17e71e5
--- /dev/null
+++ b/Rules/AvoidGeneralCatch.cs
@@ -0,0 +1,110 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Collections.Generic;
+using System.Management.Automation.Language;
+using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
+#if !CORECLR
+using System.ComponentModel.Composition;
+#endif
+using System.Globalization;
+
+namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
+{
+ ///
+ /// AvoidGeneralCatch: Check if any empty catch block is used.
+ ///
+#if !CORECLR
+[Export(typeof(IScriptRule))]
+#endif
+ public class AvoidGeneralCatch : IScriptRule
+ {
+ ///
+ /// AnalyzeScript: Analyze the script to check if any empty catch block is used.
+ ///
+ public IEnumerable AnalyzeScript(Ast ast, string fileName)
+ {
+ if (ast == null) throw new ArgumentNullException(Strings.NullAstErrorMessage);
+
+ // Finds all CommandAsts.
+ IEnumerable foundAsts = ast.FindAll(testAst => testAst is CatchClauseAst, true);
+
+ // Iterates all CatchClauseAst and check the statements count.
+ foreach (Ast foundAst in foundAsts)
+ {
+ CatchClauseAst catchAst = (CatchClauseAst)foundAst;
+
+//code goes here
+ /* if (catchAst.Body.Statements.Count == 0)
+ no need for statement check?
+
+ {
+ # yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
+ # catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
+ if getName == RuntimeExcewption>
+ is getName catch clause?
+
+ }
+ */
+ }
+ }
+
+ ///
+ /// GetName: Retrieves the name of this rule.
+ ///
+ /// The name of this rule
+ public string GetName()
+ {
+ return string.Format(CultureInfo.CurrentCulture, Strings.NameSpaceFormat, GetSourceName(), Strings.AvoidGeneralCatchName);
+ }
+
+ ///
+ /// GetCommonName: Retrieves the common name of this rule.
+ ///
+ /// The common name of this rule
+ public string GetCommonName()
+ {
+ return string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchCommonName);
+ }
+
+ ///
+ /// GetDescription: Retrieves the description of this rule.
+ ///
+ /// The description of this rule
+ public string GetDescription()
+ {
+ return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingGeneralCatchDescription);
+ }
+
+ ///
+ /// Method: Retrieves the type of the rule: builtin, managed or module.
+ ///
+ public SourceType GetSourceType()
+ {
+ return SourceType.Builtin;
+ }
+
+ ///
+ /// GetSeverity: Retrieves the severity of the rule: error, warning of information.
+ ///
+ ///
+ public RuleSeverity GetSeverity()
+ {
+ return RuleSeverity.Warning;
+ }
+
+ ///
+ /// Method: Retrieves the module/assembly name the rule is from.
+ ///
+ public string GetSourceName()
+ {
+ return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
+ }
+
+ }
+}
+
+
+
+
From 35f220fcd6db0e87528327c51bc678b7473f08cb Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Mon, 7 Nov 2022 23:10:43 +0000
Subject: [PATCH 2/7] Major changes
---
.idea/.gitignore | 8 ++++++++
.idea/PSScriptAnalyzer.iml | 8 ++++++++
.idea/modules.xml | 8 ++++++++
.idea/vcs.xml | 6 ++++++
Rules/AvoidGeneralCatch.cs | 32 ++++++++++++++++++++------------
Rules/Strings.resx | 9 +++++++++
6 files changed, 59 insertions(+), 12 deletions(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/PSScriptAnalyzer.iml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 000000000..13566b81b
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/PSScriptAnalyzer.iml b/.idea/PSScriptAnalyzer.iml
new file mode 100644
index 000000000..bc2cd8740
--- /dev/null
+++ b/.idea/PSScriptAnalyzer.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 000000000..e3dd726b6
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..94a25f7f4
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Rules/AvoidGeneralCatch.cs b/Rules/AvoidGeneralCatch.cs
index 9e17e71e5..662db458a 100644
--- a/Rules/AvoidGeneralCatch.cs
+++ b/Rules/AvoidGeneralCatch.cs
@@ -13,7 +13,7 @@
namespace Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules
{
///
- /// AvoidGeneralCatch: Check if any empty catch block is used.
+ /// AvoidGeneralCatch: Check if catch clause type is RuntimeException and caution against using it
///
#if !CORECLR
[Export(typeof(IScriptRule))]
@@ -35,18 +35,25 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
{
CatchClauseAst catchAst = (CatchClauseAst)foundAst;
-//code goes here
- /* if (catchAst.Body.Statements.Count == 0)
- no need for statement check?
+ //CatchClauseAst catchAst = (CatchClauseAst)foundAst;
+ if (catchAst.CatchTypes.Count == 0) {
+ yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
+ catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
+ }
+
+ else{
+
+ print("successful compile");
- {
- # yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
- # catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
- if getName == RuntimeExcewption>
- is getName catch clause?
-
+ foreach (CatchClauseAst catchAst in Catch.CatchTypes) {
+ if (catchAst.type == RuntimeException) {
+
+ yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
+ catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
+
+ }
+ }
}
- */
}
}
@@ -101,10 +108,11 @@ public string GetSourceName()
{
return string.Format(CultureInfo.CurrentCulture, Strings.SourceName);
}
-
}
}
+
+
diff --git a/Rules/Strings.resx b/Rules/Strings.resx
index 20b04712d..9981a2952 100644
--- a/Rules/Strings.resx
+++ b/Rules/Strings.resx
@@ -126,9 +126,15 @@
Empty catch blocks are considered poor design decisions because if an error occurs in the try block, this error is simply swallowed and not acted upon. While this does not inherently lead to bad things. It can and this should be avoided if possible. To fix a violation of this rule, using Write-Error or throw statements in catch blocks.
+
+ A catch block with the type system.management.automation.runtimeexception should not be used in a catch block as it will incorrectly catch all exceptions
+
Avoid Using Empty Catch Block
+
+ Avoid using General Catch type
+
The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command. It can be extraordinarily powerful so it is not that you want to never use it but you need to be very careful about using it. In particular, you are probably on safe ground if the data only comes from the program itself. If you include any data provided from the user - you need to protect yourself from Code Injection. To fix a violation of this rule, please remove Invoke-Expression from script and find other options instead.
@@ -513,6 +519,9 @@
Empty catch block is used. Please use Write-Error or throw statements in catch blocks.
+
+ Runtime Exception is used in catch block. Avoid using this as it will catch all exceptions.
+
'{0}' is an alias of '{1}'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.
From 3a5cca1204f1acac0fe6ac2dfac75481e3c0cf47 Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Tue, 8 Nov 2022 22:56:15 +0000
Subject: [PATCH 3/7] Compiling build
---
Rules/AvoidGeneralCatch.cs | 10 +++++-----
Rules/Strings.Designer.cs | 36 ++++++++++++++++++++++++++++++++++++
Rules/Strings.resx | 5 ++++-
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/Rules/AvoidGeneralCatch.cs b/Rules/AvoidGeneralCatch.cs
index 662db458a..5a0918336 100644
--- a/Rules/AvoidGeneralCatch.cs
+++ b/Rules/AvoidGeneralCatch.cs
@@ -43,13 +43,13 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
else{
- print("successful compile");
+ //print("successful compile");
- foreach (CatchClauseAst catchAst in Catch.CatchTypes) {
- if (catchAst.type == RuntimeException) {
+ foreach (TypeConstraintAst caughtAst in catchAst.CatchTypes) {
+ if (caughtAst.TypeName.FullName.Equals("runtimeexception")) {
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
- catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
+ caughtAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
}
}
@@ -81,7 +81,7 @@ public string GetCommonName()
/// The description of this rule
public string GetDescription()
{
- return string.Format(CultureInfo.CurrentCulture, Strings.AvoidUsingGeneralCatchDescription);
+ return string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchDescription);
}
///
diff --git a/Rules/Strings.Designer.cs b/Rules/Strings.Designer.cs
index 30d0a7321..e349bcf97 100644
--- a/Rules/Strings.Designer.cs
+++ b/Rules/Strings.Designer.cs
@@ -284,6 +284,15 @@ internal static string AvoidEmptyCatchBlockError {
return ResourceManager.GetString("AvoidEmptyCatchBlockError", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to General catch block is used.
+ ///
+ internal static string AvoidGeneralCatchError {
+ get {
+ return ResourceManager.GetString("AvoidLongGeneralCatchError", resourceCulture);
+ }
+ }
///
/// Looks up a localized string similar to Avoid global aliases..
@@ -1013,6 +1022,15 @@ internal static string AvoidUsingEmptyCatchBlockCommonName {
return ResourceManager.GetString("AvoidUsingEmptyCatchBlockCommonName", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Avoid Using catch block of type RuntimeException.
+ ///
+ internal static string AvoidGeneralCatchCommonName {
+ get {
+ return ResourceManager.GetString("AvoidGeneralCatchCommonName", resourceCulture);
+ }
+ }
///
/// Looks up a localized string similar to Empty catch blocks are considered poor design decisions because if an error occurs in the try block, this error is simply swallowed and not acted upon. While this does not inherently lead to bad things. It can and this should be avoided if possible. To fix a violation of this rule, using Write-Error or throw statements in catch blocks..
@@ -1022,6 +1040,15 @@ internal static string AvoidUsingEmptyCatchBlockDescription {
return ResourceManager.GetString("AvoidUsingEmptyCatchBlockDescription", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to Empty catch blocks are considered poor design decisions because if an error occurs in the try block, this error is simply swallowed and not acted upon. While this does not inherently lead to bad things. It can and this should be avoided if possible. To fix a violation of this rule, using Write-Error or throw statements in catch blocks..
+ ///
+ internal static string AvoidGeneralCatchDescription {
+ get {
+ return ResourceManager.GetString("AvoidGeneralCatchDescription", resourceCulture);
+ }
+ }
///
/// Looks up a localized string similar to AvoidUsingEmptyCatchBlock.
@@ -1031,6 +1058,15 @@ internal static string AvoidUsingEmptyCatchBlockName {
return ResourceManager.GetString("AvoidUsingEmptyCatchBlockName", resourceCulture);
}
}
+
+ ///
+ /// Looks up a localized string similar to AvoidGeneralCatchBlock.
+ ///
+ internal static string AvoidGeneralCatchName {
+ get {
+ return ResourceManager.GetString("AvoidUsingEmptyCatchName", resourceCulture);
+ }
+ }
///
/// Looks up a localized string similar to Avoid Using Internal URLs.
diff --git a/Rules/Strings.resx b/Rules/Strings.resx
index 9981a2952..5d2f0546a 100644
--- a/Rules/Strings.resx
+++ b/Rules/Strings.resx
@@ -126,7 +126,7 @@
Empty catch blocks are considered poor design decisions because if an error occurs in the try block, this error is simply swallowed and not acted upon. While this does not inherently lead to bad things. It can and this should be avoided if possible. To fix a violation of this rule, using Write-Error or throw statements in catch blocks.
-
+
A catch block with the type system.management.automation.runtimeexception should not be used in a catch block as it will incorrectly catch all exceptions
@@ -384,6 +384,9 @@
AvoidUsingEmptyCatchBlock
+
+ AvoidGeneralCatch
+
AvoidUsingInvokeExpression
From 333744c699b1672c62f6174ecc870043f5c343b1 Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Thu, 17 Nov 2022 17:09:49 +0000
Subject: [PATCH 4/7] "minor changes and testing implementations"
---
Rules/AvoidGeneralCatch.cs | 12 +++++------
Tests/Rules/AvoidGeneralCatch.ps1 | 12 +++++++++++
Tests/Rules/AvoidGeneralCatch.tests.ps1 | 28 +++++++++++++++++++++++++
3 files changed, 45 insertions(+), 7 deletions(-)
create mode 100644 Tests/Rules/AvoidGeneralCatch.ps1
create mode 100644 Tests/Rules/AvoidGeneralCatch.tests.ps1
diff --git a/Rules/AvoidGeneralCatch.cs b/Rules/AvoidGeneralCatch.cs
index 5a0918336..68995ab75 100644
--- a/Rules/AvoidGeneralCatch.cs
+++ b/Rules/AvoidGeneralCatch.cs
@@ -35,18 +35,16 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
{
CatchClauseAst catchAst = (CatchClauseAst)foundAst;
- //CatchClauseAst catchAst = (CatchClauseAst)foundAst;
- if (catchAst.CatchTypes.Count == 0) {
+ if (catchAst.CatchTypes.Count == 0)
+ {
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
}
-
- else{
-
- //print("successful compile");
+ else
+ {
foreach (TypeConstraintAst caughtAst in catchAst.CatchTypes) {
- if (caughtAst.TypeName.FullName.Equals("runtimeexception")) {
+ if (string.Equals(caughtAst.TypeName.FullName, "RuntimeException", StringComparison.CurrentCultureIgnoreCase) | string.Equals(caughtAst.TypeName.FullName, "System.Management.Automation.RuntimeException", StringComparison.CurrentCultureIgnoreCase)); {
yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
caughtAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
diff --git a/Tests/Rules/AvoidGeneralCatch.ps1 b/Tests/Rules/AvoidGeneralCatch.ps1
new file mode 100644
index 000000000..c3ed2ff8c
--- /dev/null
+++ b/Tests/Rules/AvoidGeneralCatch.ps1
@@ -0,0 +1,12 @@
+try
+{
+ 1/0
+}
+catch [System.Management.Automation.RuntimeException]
+{
+
+}
+finally
+{
+ Write-Host "cleaning up ..."
+}
\ No newline at end of file
diff --git a/Tests/Rules/AvoidGeneralCatch.tests.ps1 b/Tests/Rules/AvoidGeneralCatch.tests.ps1
new file mode 100644
index 000000000..3bc6cbe7d
--- /dev/null
+++ b/Tests/Rules/AvoidGeneralCatch.tests.ps1
@@ -0,0 +1,28 @@
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License.
+
+BeforeAll {
+ $violationMessage = "Runtime Exception as catch block type is used. Please use Write-Error or throw statements in catch blocks."
+ $violationName = "PSAvoidGeneralCatch"
+ $violations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidGeneralCatch.ps1 | Where-Object {$_.RuleName -eq $violationName}
+ #$noViolations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidEmptyCatchBlockNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
+}
+
+Describe "UseDeclaredVarsMoreThanAssignments" {
+ Context "When there are violations" {
+ It "has 2 avoid using empty Catch block violations" {
+ $violations.Count | Should -Be 2
+ }
+
+ It "has the correct description message" {
+ $violations[0].Message | Should -Match $violationMessage
+ }
+
+ }
+
+ Context "When there are no violations" {
+ It "returns no violations" {
+ $noViolations.Count | Should -Be 0
+ }
+ }
+}
From 4bb6e532b0a65dfc751b943636f7d941c24937c5 Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Thu, 1 Dec 2022 20:45:11 +0000
Subject: [PATCH 5/7] testing implementation
---
Tests/Rules/AvoidGeneralCatch.ps1 | 12 ++++++++++--
Tests/Rules/AvoidGeneralCatch.tests.ps1 | 18 ++++--------------
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/Tests/Rules/AvoidGeneralCatch.ps1 b/Tests/Rules/AvoidGeneralCatch.ps1
index c3ed2ff8c..51c3ad73d 100644
--- a/Tests/Rules/AvoidGeneralCatch.ps1
+++ b/Tests/Rules/AvoidGeneralCatch.ps1
@@ -2,11 +2,19 @@ try
{
1/0
}
+catch [DivideByZeroException]
+{
+ "catch divide by zero exception"
+}
catch [System.Management.Automation.RuntimeException]
{
-
+ "catch RuntimeException"
+}
+catch
+{
+ "No exception"
}
finally
{
- Write-Host "cleaning up ..."
+ "cleaning up ..."
}
\ No newline at end of file
diff --git a/Tests/Rules/AvoidGeneralCatch.tests.ps1 b/Tests/Rules/AvoidGeneralCatch.tests.ps1
index 3bc6cbe7d..8c7781e00 100644
--- a/Tests/Rules/AvoidGeneralCatch.tests.ps1
+++ b/Tests/Rules/AvoidGeneralCatch.tests.ps1
@@ -5,24 +5,14 @@ BeforeAll {
$violationMessage = "Runtime Exception as catch block type is used. Please use Write-Error or throw statements in catch blocks."
$violationName = "PSAvoidGeneralCatch"
$violations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidGeneralCatch.ps1 | Where-Object {$_.RuleName -eq $violationName}
- #$noViolations = Invoke-ScriptAnalyzer $PSScriptRoot\AvoidEmptyCatchBlockNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
}
Describe "UseDeclaredVarsMoreThanAssignments" {
- Context "When there are violations" {
- It "has 2 avoid using empty Catch block violations" {
- $violations.Count | Should -Be 2
- }
-
- It "has the correct description message" {
- $violations[0].Message | Should -Match $violationMessage
- }
-
+ It "has 2 violations satisfying AvoidGeneralCatch rule" {
+ $violations.Count | Should -Be 2
}
- Context "When there are no violations" {
- It "returns no violations" {
- $noViolations.Count | Should -Be 0
- }
+ It "has the correct description message" {
+ $violations[0].Message | Should -Match $violationMessage
}
}
From 998050d1514b29377e6fb3319754817d9150257c Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Mon, 12 Dec 2022 22:31:29 +0000
Subject: [PATCH 6/7] Implemented rule including tests
---
Rules/AvoidGeneralCatch.cs | 17 ++++++++++++++++-
Rules/Strings.Designer.cs | 11 ++++++++++-
Rules/Strings.resx | 3 +++
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/Rules/AvoidGeneralCatch.cs b/Rules/AvoidGeneralCatch.cs
index 68995ab75..c5e27119a 100644
--- a/Rules/AvoidGeneralCatch.cs
+++ b/Rules/AvoidGeneralCatch.cs
@@ -37,10 +37,24 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
if (catchAst.CatchTypes.Count == 0)
{
- yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
+ yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchErrorEmpty),
catchAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
}
else
+ {
+
+ foreach (TypeConstraintAst caughtAst in catchAst.CatchTypes) {
+ if (string.Equals(caughtAst.TypeName.FullName, "RuntimeException", StringComparison.CurrentCultureIgnoreCase) || string.Equals(caughtAst.TypeName.FullName, "System.Management.Automation.RuntimeException", StringComparison.CurrentCultureIgnoreCase)) {
+
+ yield return new DiagnosticRecord(string.Format(CultureInfo.CurrentCulture, Strings.AvoidGeneralCatchError),
+ caughtAst.Extent, GetName(), DiagnosticSeverity.Warning, fileName);
+
+ }
+ }
+ }
+
+/**
+ if (catchAst.CatchTypes.Count != 0)
{
foreach (TypeConstraintAst caughtAst in catchAst.CatchTypes) {
@@ -52,6 +66,7 @@ public IEnumerable AnalyzeScript(Ast ast, string fileName)
}
}
}
+ **/
}
}
diff --git a/Rules/Strings.Designer.cs b/Rules/Strings.Designer.cs
index e349bcf97..ee252f196 100644
--- a/Rules/Strings.Designer.cs
+++ b/Rules/Strings.Designer.cs
@@ -290,7 +290,16 @@ internal static string AvoidEmptyCatchBlockError {
///
internal static string AvoidGeneralCatchError {
get {
- return ResourceManager.GetString("AvoidLongGeneralCatchError", resourceCulture);
+ return ResourceManager.GetString("AvoidGeneralCatchError", resourceCulture);
+ }
+ }
+
+ ///
+ /// Looks up a localized string when no specific exception is caught.
+ ///
+ internal static string AvoidGeneralCatchErrorEmpty {
+ get {
+ return ResourceManager.GetString("AvoidGeneralCatchErrorEmpty", resourceCulture);
}
}
diff --git a/Rules/Strings.resx b/Rules/Strings.resx
index 5d2f0546a..723dab010 100644
--- a/Rules/Strings.resx
+++ b/Rules/Strings.resx
@@ -525,6 +525,9 @@
Runtime Exception is used in catch block. Avoid using this as it will catch all exceptions.
+
+ No specific exception is being caught.
+
'{0}' is an alias of '{1}'. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.
From b445a835b16475f7e4981a25595841ee446c19c9 Mon Sep 17 00:00:00 2001
From: "[Cruaaa]" <[lmurray2200@gmail.com]>
Date: Mon, 12 Dec 2022 23:00:18 +0000
Subject: [PATCH 7/7] Addition of copyright header to file
---
Tests/Rules/AvoidGeneralCatch.ps1 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/Tests/Rules/AvoidGeneralCatch.ps1 b/Tests/Rules/AvoidGeneralCatch.ps1
index 51c3ad73d..b2f72d753 100644
--- a/Tests/Rules/AvoidGeneralCatch.ps1
+++ b/Tests/Rules/AvoidGeneralCatch.ps1
@@ -1,3 +1,6 @@
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License.
+
try
{
1/0