1010using System . Threading ;
1111using System . Threading . Tasks ;
1212using Microsoft . Extensions . Logging ;
13- using Microsoft . PowerShell . EditorServices . Engine . Logging ;
1413using Microsoft . PowerShell . EditorServices . Engine . Services ;
1514using Microsoft . PowerShell . EditorServices . Engine . Services . PowerShellContext ;
1615using OmniSharp . Extensions . DebugAdapter . Protocol . Events ;
@@ -255,7 +254,7 @@ public async Task<Unit> Handle(PsesAttachRequestArguments request, CancellationT
255254 _logger . LogInformation (
256255 $ "Attach request aborted, received { request . ProcessId } for processId.") ;
257256
258- throw new Exception ( "User aborted attach to PowerShell host process." ) ;
257+ throw new RpcErrorException ( 0 , "User aborted attach to PowerShell host process." ) ;
259258 }
260259
261260 StringBuilder errorMessages = new StringBuilder ( ) ;
@@ -264,11 +263,11 @@ public async Task<Unit> Handle(PsesAttachRequestArguments request, CancellationT
264263 {
265264 if ( runspaceVersion . Version . Major < 4 )
266265 {
267- throw new Exception ( $ "Remote sessions are only available with PowerShell 4 and higher (current session is { runspaceVersion . Version } ).") ;
266+ throw new RpcErrorException ( 0 , $ "Remote sessions are only available with PowerShell 4 and higher (current session is { runspaceVersion . Version } ).") ;
268267 }
269268 else if ( _powerShellContextService . CurrentRunspace . Location == RunspaceLocation . Remote )
270269 {
271- throw new Exception ( $ "Cannot attach to a process in a remote session when already in a remote session.") ;
270+ throw new RpcErrorException ( 0 , $ "Cannot attach to a process in a remote session when already in a remote session.") ;
272271 }
273272
274273 await _powerShellContextService . ExecuteScriptStringAsync (
@@ -277,7 +276,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
277276
278277 if ( errorMessages . Length > 0 )
279278 {
280- throw new Exception ( $ "Could not establish remote session to computer '{ request . ComputerName } '") ;
279+ throw new RpcErrorException ( 0 , $ "Could not establish remote session to computer '{ request . ComputerName } '") ;
281280 }
282281
283282 _debugStateService . IsRemoteAttach = true ;
@@ -287,7 +286,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
287286 {
288287 if ( runspaceVersion . Version . Major < 5 )
289288 {
290- throw new Exception ( $ "Attaching to a process is only available with PowerShell 5 and higher (current session is { runspaceVersion . Version } ).") ;
289+ throw new RpcErrorException ( 0 , $ "Attaching to a process is only available with PowerShell 5 and higher (current session is { runspaceVersion . Version } ).") ;
291290 }
292291
293292 await _powerShellContextService . ExecuteScriptStringAsync (
@@ -296,14 +295,14 @@ await _powerShellContextService.ExecuteScriptStringAsync(
296295
297296 if ( errorMessages . Length > 0 )
298297 {
299- throw new Exception ( $ "Could not attach to process '{ processId } '") ;
298+ throw new RpcErrorException ( 0 , $ "Could not attach to process '{ processId } '") ;
300299 }
301300 }
302301 else if ( customPipeNameIsSet )
303302 {
304303 if ( runspaceVersion . Version < s_minVersionForCustomPipeName )
305304 {
306- throw new Exception ( $ "Attaching to a process with CustomPipeName is only available with PowerShell 6.2 and higher (current session is { runspaceVersion . Version } ).") ;
305+ throw new RpcErrorException ( 0 , $ "Attaching to a process with CustomPipeName is only available with PowerShell 6.2 and higher (current session is { runspaceVersion . Version } ).") ;
307306 }
308307
309308 await _powerShellContextService . ExecuteScriptStringAsync (
@@ -312,15 +311,15 @@ await _powerShellContextService.ExecuteScriptStringAsync(
312311
313312 if ( errorMessages . Length > 0 )
314313 {
315- throw new Exception ( $ "Could not attach to process with CustomPipeName: '{ request . CustomPipeName } '") ;
314+ throw new RpcErrorException ( 0 , $ "Could not attach to process with CustomPipeName: '{ request . CustomPipeName } '") ;
316315 }
317316 }
318317 else if ( request . ProcessId != "current" )
319318 {
320319 _logger . LogError (
321320 $ "Attach request failed, '{ request . ProcessId } ' is an invalid value for the processId.") ;
322321
323- throw new Exception ( "A positive integer must be specified for the processId field." ) ;
322+ throw new RpcErrorException ( 0 , "A positive integer must be specified for the processId field." ) ;
324323 }
325324
326325 // Clear any existing breakpoints before proceeding
@@ -343,7 +342,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
343342 _logger . LogError (
344343 $ "Attach request failed, '{ request . RunspaceId } ' is an invalid value for the processId.") ;
345344
346- throw new Exception ( "A positive integer must be specified for the RunspaceId field." ) ;
345+ throw new RpcErrorException ( 0 , "A positive integer must be specified for the RunspaceId field." ) ;
347346 }
348347
349348 debugRunspaceCmd = $ "\n Debug-Runspace -Id { runspaceId } ";
0 commit comments