File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,12 @@ internal ProgramContext(ReadOnlyMemory<string> arguments)
3939 // The following methods must never throw.
4040
4141 [ SuppressMessage ( "" , "CA1031" ) ]
42- internal void RaiseUnhandledException ( Exception exception )
42+ internal bool RaiseUnhandledException ( Exception exception )
4343 {
4444 var ev = UnhandledException ;
4545
4646 if ( ev == null )
47- return ;
47+ return false ;
4848
4949 foreach ( var dg in ev . GetInvocationList ( ) )
5050 {
@@ -56,6 +56,8 @@ internal void RaiseUnhandledException(Exception exception)
5656 {
5757 }
5858 }
59+
60+ return true ;
5961 }
6062
6163 [ SuppressMessage ( "" , "CA1031" ) ]
Original file line number Diff line number Diff line change @@ -30,7 +30,12 @@ public static async Task RunAsync<TProgram>(ReadOnlyMemory<string> arguments)
3030
3131 domain . UnhandledException += ( _ , e ) =>
3232 {
33- context . RaiseUnhandledException ( ( Exception ) e . ExceptionObject ) ;
33+ var ex = ( Exception ) e . ExceptionObject ;
34+
35+ // The terminal might be in raw mode when this happens and checking IsRawMode is racey. To ensure sensible
36+ // output, just always use CRLF here.
37+ if ( ! context . RaiseUnhandledException ( ex ) )
38+ Terminal . Error ( $ "Unhandled exception. { ex . ToString ( ) . ReplaceLineEndings ( "\r \n " ) } \r \n ") ;
3439
3540 // Most users expect ProcessExit to run on both normal and abnormal termination. This call makes that happen
3641 // and also ensures that the terminal cleanup we do in ProcessExit runs. One unfortunate downside of this
You can’t perform that action at this time.
0 commit comments