Skip to content

Commit a012dec

Browse files
Do not attempt id and category inference for the error to throw when processing the argument of Invoke-ScriptAnalyzer -Settings results in an exception
1 parent 0472359 commit a012dec

File tree

1 file changed

+5
-42
lines changed

1 file changed

+5
-42
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -328,48 +328,11 @@ protected override void BeginProcessing()
328328
}
329329
catch (Exception e)
330330
{
331-
string errorId;
332-
ErrorCategory errorCategory;
333-
switch (e)
334-
{
335-
case ArgumentException _:
336-
errorId = "InvalidSettingsArgument";
337-
errorCategory = ErrorCategory.InvalidArgument;
338-
break;
339-
case InvalidDataException _:
340-
errorId = "InvalidSettingsData";
341-
errorCategory = ErrorCategory.InvalidData;
342-
break;
343-
case InvalidOperationException _:
344-
errorId = "InvalidPathForProvider"; // InvalidOperationException can arise from provider-specific limitations interacting with a settings path (e.g. wildcards, home, containers, etc.).
345-
errorCategory = ErrorCategory.InvalidOperation;
346-
break;
347-
case InternalBufferOverflowException _:
348-
case PathTooLongException _:
349-
errorId = "PathOrSettingsExceededLimits";
350-
errorCategory = ErrorCategory.LimitsExceeded;
351-
break;
352-
case NotSupportedException _:
353-
errorId = "PathOrSettingNotSupported";
354-
errorCategory = ErrorCategory.NotEnabled;
355-
break;
356-
case DirectoryNotFoundException _:
357-
case System.IO.DriveNotFoundException _:
358-
case System.Management.Automation.DriveNotFoundException _:
359-
case FileNotFoundException _:
360-
case ItemNotFoundException _:
361-
case ProviderNotFoundException _:
362-
errorId = "SettingsNotFound";
363-
errorCategory = ErrorCategory.ObjectNotFound;
364-
break;
365-
default:
366-
errorId = "SettingsNotLoadable";
367-
errorCategory = ErrorCategory.NotSpecified;
368-
break;
369-
}
370-
371-
var errorRecord = new ErrorRecord(e, errorId, errorCategory, this.settings);
372-
this.ThrowTerminatingError(errorRecord);
331+
this.ThrowTerminatingError(new ErrorRecord(
332+
e,
333+
"SettingsNotProcessable",
334+
ErrorCategory.NotSpecified,
335+
this.settings));
373336
}
374337

375338
ScriptAnalyzer.Instance.Initialize(

0 commit comments

Comments
 (0)