Skip to content

Commit 52d5494

Browse files
author
Kapil Borle
committed
Check for initialization error
1 parent 4909fb4 commit 52d5494

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Rules/UseCompatibleCmdlets.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class UseCompatibleCmdlets : AstVisitor, IScriptRule
4141
private Dictionary<string, dynamic> platformSpecMap;
4242
private string scriptPath;
4343
private bool IsInitialized;
44+
private bool hasInitializationError;
4445
private string referenceFile;
4546
private readonly string defaultReferenceFile = "desktop-5.1.14393.206-windows.json";
4647

@@ -126,6 +127,11 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
126127
Initialize();
127128
}
128129

130+
if (hasInitializationError)
131+
{
132+
yield break;
133+
}
134+
129135
if (ast == null)
130136
{
131137
throw new ArgumentNullException("ast");
@@ -217,6 +223,9 @@ private void Initialize()
217223
/// </summary>
218224
private void SetupCmdletsDictionary()
219225
{
226+
// If the method encounters any error, it returns early
227+
// which implies there is an initialization error
228+
hasInitializationError = true;
220229
Dictionary<string, object> ruleArgs = Helper.Instance.GetRuleArguments(GetName());
221230
if (ruleArgs == null)
222231
{
@@ -316,6 +325,9 @@ private void SetupCmdletsDictionary()
316325
}
317326

318327
ProcessDirectory(settingsPath);
328+
329+
// reached this point, so no error
330+
hasInitializationError = false;
319331
}
320332

321333
/// <summary>

0 commit comments

Comments
 (0)