File tree Expand file tree Collapse file tree
PSCompatibilityCollector/Microsoft.PowerShell.CrossCompatibility/Commands Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments