10
10
using System . Threading ;
11
11
using System . Threading . Tasks ;
12
12
using Microsoft . Extensions . Logging ;
13
- using Microsoft . PowerShell . EditorServices . Engine . Logging ;
14
13
using Microsoft . PowerShell . EditorServices . Engine . Services ;
15
14
using Microsoft . PowerShell . EditorServices . Engine . Services . PowerShellContext ;
16
15
using OmniSharp . Extensions . DebugAdapter . Protocol . Events ;
@@ -255,7 +254,7 @@ public async Task<Unit> Handle(PsesAttachRequestArguments request, CancellationT
255
254
_logger . LogInformation (
256
255
$ "Attach request aborted, received { request . ProcessId } for processId.") ;
257
256
258
- throw new Exception ( "User aborted attach to PowerShell host process." ) ;
257
+ throw new RpcErrorException ( 0 , "User aborted attach to PowerShell host process." ) ;
259
258
}
260
259
261
260
StringBuilder errorMessages = new StringBuilder ( ) ;
@@ -264,11 +263,11 @@ public async Task<Unit> Handle(PsesAttachRequestArguments request, CancellationT
264
263
{
265
264
if ( runspaceVersion . Version . Major < 4 )
266
265
{
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 } ).") ;
268
267
}
269
268
else if ( _powerShellContextService . CurrentRunspace . Location == RunspaceLocation . Remote )
270
269
{
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.") ;
272
271
}
273
272
274
273
await _powerShellContextService . ExecuteScriptStringAsync (
@@ -277,7 +276,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
277
276
278
277
if ( errorMessages . Length > 0 )
279
278
{
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 } '") ;
281
280
}
282
281
283
282
_debugStateService . IsRemoteAttach = true ;
@@ -287,7 +286,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
287
286
{
288
287
if ( runspaceVersion . Version . Major < 5 )
289
288
{
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 } ).") ;
291
290
}
292
291
293
292
await _powerShellContextService . ExecuteScriptStringAsync (
@@ -296,14 +295,14 @@ await _powerShellContextService.ExecuteScriptStringAsync(
296
295
297
296
if ( errorMessages . Length > 0 )
298
297
{
299
- throw new Exception ( $ "Could not attach to process '{ processId } '") ;
298
+ throw new RpcErrorException ( 0 , $ "Could not attach to process '{ processId } '") ;
300
299
}
301
300
}
302
301
else if ( customPipeNameIsSet )
303
302
{
304
303
if ( runspaceVersion . Version < s_minVersionForCustomPipeName )
305
304
{
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 } ).") ;
307
306
}
308
307
309
308
await _powerShellContextService . ExecuteScriptStringAsync (
@@ -312,15 +311,15 @@ await _powerShellContextService.ExecuteScriptStringAsync(
312
311
313
312
if ( errorMessages . Length > 0 )
314
313
{
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 } '") ;
316
315
}
317
316
}
318
317
else if ( request . ProcessId != "current" )
319
318
{
320
319
_logger . LogError (
321
320
$ "Attach request failed, '{ request . ProcessId } ' is an invalid value for the processId.") ;
322
321
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." ) ;
324
323
}
325
324
326
325
// Clear any existing breakpoints before proceeding
@@ -343,7 +342,7 @@ await _powerShellContextService.ExecuteScriptStringAsync(
343
342
_logger . LogError (
344
343
$ "Attach request failed, '{ request . RunspaceId } ' is an invalid value for the processId.") ;
345
344
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." ) ;
347
346
}
348
347
349
348
debugRunspaceCmd = $ "\n Debug-Runspace -Id { runspaceId } ";
0 commit comments