File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
System.CommandLine/Builder Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -109,6 +109,20 @@ public async Task Declaration_of_UseExceptionHandler_can_come_before_other_middl
109
109
. Contain ( "oops!" ) ;
110
110
}
111
111
112
+ [ Fact ]
113
+ public async Task When_thrown_exception_is_from_cancelation_no_output_is_generated ( )
114
+ {
115
+ int resultCode = await new CommandLineBuilder ( )
116
+ . AddCommand ( new Command ( "the-command" ) )
117
+ . UseExceptionHandler ( )
118
+ . UseMiddleware ( _ => throw new OperationCanceledException ( ) )
119
+ . Build ( )
120
+ . InvokeAsync ( "the-command" , _console ) ;
121
+
122
+ _console . Out . ToString ( ) . Should ( ) . BeEmpty ( ) ;
123
+ resultCode . Should ( ) . NotBe ( 0 ) ;
124
+ }
125
+
112
126
[ Fact ]
113
127
public async Task UseExceptionHandler_output_can_be_customized ( )
114
128
{
Original file line number Diff line number Diff line change @@ -290,14 +290,16 @@ public static CommandLineBuilder UseExceptionHandler(
290
290
291
291
void Default ( Exception exception , InvocationContext context )
292
292
{
293
- context . Console . ResetTerminalForegroundColor ( ) ;
294
- context . Console . SetTerminalForegroundRed ( ) ;
295
-
296
- context . Console . Error . Write ( "Unhandled exception: " ) ;
297
- context . Console . Error . WriteLine ( exception . ToString ( ) ) ;
293
+ if ( ! ( exception is OperationCanceledException ) )
294
+ {
295
+ context . Console . ResetTerminalForegroundColor ( ) ;
296
+ context . Console . SetTerminalForegroundRed ( ) ;
298
297
299
- context . Console . ResetTerminalForegroundColor ( ) ;
298
+ context . Console . Error . Write ( "Unhandled exception: " ) ;
299
+ context . Console . Error . WriteLine ( exception . ToString ( ) ) ;
300
300
301
+ context . Console . ResetTerminalForegroundColor ( ) ;
302
+ }
301
303
context . ResultCode = 1 ;
302
304
}
303
305
}
You can’t perform that action at this time.
0 commit comments