Skip to content

Commit ab506af

Browse files
Robert Holtrjmholt
authored andcommitted
Update validation cmdlet
1 parent 89a7ae1 commit ab506af

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/AssertPSCompatibilityProfileIsValidCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected override void ProcessRecord()
4343
foreach (Exception error in errors)
4444
{
4545
// Writing errors will set $? = $false
46-
this.WriteExceptionAsWarning(error);
46+
this.WriteExceptionAsError(error);
4747
}
4848
}
4949
}

PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands/CommandUtilities.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ public static void WriteExceptionAsWarning(
3030
cmdlet.WriteWarning(exception.ToString());
3131
}
3232

33+
/// <summary>
34+
/// Writes a .NET exception as an error.
35+
/// Has sensible defaults for optional parameters.
36+
/// </summary>
37+
/// <param name="cmdlet">The cmdlet writing the error.</param>
38+
/// <param name="exception">The exception to write as an error.</param>
39+
/// <param name="errorId">The error ID to associate with the exception.</param>
40+
/// <param name="errorCategory">The category to assign the exception to.</param>
41+
/// <param name="targetObject">The target object of the error, defaults to null.</param>
42+
public static void WriteExceptionAsError(
43+
this Cmdlet cmdlet,
44+
Exception exception,
45+
string errorId = "CompatibilityCollectionError",
46+
ErrorCategory errorCategory = ErrorCategory.ReadError,
47+
object targetObject = null)
48+
{
49+
cmdlet.WriteError(
50+
new ErrorRecord(
51+
exception,
52+
errorId,
53+
errorCategory,
54+
targetObject));
55+
}
56+
3357
/// <summary>
3458
/// Normalize a given path to an absolute path using PowerShell APIs
3559
/// available from within a cmdlet.

0 commit comments

Comments
 (0)