Skip to content

Commit b407e8e

Browse files
travisclagronebergmeister
authored andcommitted
Actionabilize errors from incorrect settings files (#1263)
* Annotatively research current state of exception handling surrounding settings file load invocation * Throw a contextful terminating error if processing the argument of 'Invoke-ScriptAnalyzer -Settings' results in an exception * Refine id and category of error for when processing value of `Invoke-ScriptAnalyzer -Settings` results in an exception * Revert "Annotatively research current state of exception handling surrounding settings file load invocation" This reverts commit 3bfd45b. * Do not attempt id and category inference for the error to throw when processing the argument of `Invoke-ScriptAnalyzer -Settings` results in an exception * Remove `using System.IO` * Revert "Remove `using System.IO`" This reverts commit 88ab1ec. `using System.IO` is required in Engine\Settings.cs after all. The main use is for pre-existing unqualified references to the type InvalidDataException. * Remove unused using after refactoring. Use more descriptive variable name and make error record arguments consistent with usage in other parts of the solution.
1 parent fd7663e commit b407e8e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,13 @@ protected override void BeginProcessing()
325325
? rulePaths
326326
: rulePaths.Concat(settingsCustomRulePath).ToArray();
327327
}
328-
catch
328+
catch (Exception exception)
329329
{
330-
this.WriteWarning(String.Format(CultureInfo.CurrentCulture, Strings.SettingsNotParsable));
331-
stopProcessing = true;
332-
return;
330+
this.ThrowTerminatingError(new ErrorRecord(
331+
exception,
332+
"SETTINGS_ERROR",
333+
ErrorCategory.InvalidData,
334+
this.settings));
333335
}
334336

335337
ScriptAnalyzer.Instance.Initialize(
@@ -357,7 +359,7 @@ protected override void ProcessRecord()
357359
{
358360
ProcessPath();
359361
}
360-
362+
361363
#if !PSV3
362364
// TODO Support dependency resolution for analyzing script definitions
363365
if (saveDscDependency)

0 commit comments

Comments
 (0)