Skip to content

Commit 196d1c2

Browse files
committed
Server should crash on unhandled exceptions in message loop
This change causes all unhandled exceptions to crash the server so that the user is not left with an inoperative language service. This was the expected behavior before the recent redesign changed how the exception gets propagated all the way back to the EditorServicesHost. The host will now throw the unhandled exception from the WaitForCompletion method causing the process to exit.
1 parent 9a9e2b8 commit 196d1c2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/PowerShellEditorServices.Host/EditorServicesHost.cs

+13
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ private async void OnLanguageServiceClientConnect(
193193
messageDispatcher,
194194
this.logger);
195195

196+
protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException;
197+
196198
this.editorSession =
197199
CreateSession(
198200
this.hostDetails,
@@ -252,6 +254,8 @@ private void OnDebugServiceClientConnect(object sender, TcpSocketServerChannel s
252254
messageDispatcher,
253255
this.logger);
254256

257+
protocolEndpoint.UnhandledException += ProtocolEndpoint_UnhandledException;
258+
255259
if (this.enableConsoleRepl)
256260
{
257261
this.debugAdapter =
@@ -394,6 +398,15 @@ private EditorSession CreateDebugSession(
394398
return editorSession;
395399
}
396400

401+
private void ProtocolEndpoint_UnhandledException(object sender, Exception e)
402+
{
403+
this.logger.Write(
404+
LogLevel.Error,
405+
"PowerShell Editor Services is terminating due to an unhandled exception, see previous logs for details.");
406+
407+
this.serverCompletedTask.SetException(e);
408+
}
409+
397410
#if !CoreCLR
398411
private void CurrentDomain_UnhandledException(
399412
object sender,

0 commit comments

Comments
 (0)