Skip to content

Commit

Permalink
Actionabilize errors from incorrect settings files (PowerShell#1263)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
travisclagrone authored and bergmeister committed Jun 29, 2019
1 parent fd7663e commit b407e8e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Engine/Commands/InvokeScriptAnalyzerCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,13 @@ protected override void BeginProcessing()
? rulePaths
: rulePaths.Concat(settingsCustomRulePath).ToArray();
}
catch
catch (Exception exception)
{
this.WriteWarning(String.Format(CultureInfo.CurrentCulture, Strings.SettingsNotParsable));
stopProcessing = true;
return;
this.ThrowTerminatingError(new ErrorRecord(
exception,
"SETTINGS_ERROR",
ErrorCategory.InvalidData,
this.settings));
}

ScriptAnalyzer.Instance.Initialize(
Expand Down Expand Up @@ -357,7 +359,7 @@ protected override void ProcessRecord()
{
ProcessPath();
}

#if !PSV3
// TODO Support dependency resolution for analyzing script definitions
if (saveDscDependency)
Expand Down

0 comments on commit b407e8e

Please sign in to comment.