@@ -411,53 +411,78 @@ private void HandleRequest(in ReadOnlySequence<byte> request)
411
411
{
412
412
if ( item . IsRequest && item . Request != null )
413
413
{
414
- // _logger.LogDebug("Handling Request {Method} {ResponseId}", item.Request.Method, item.Request.Id);
415
- var descriptor = _requestRouter . GetDescriptors ( item . Request ) ;
416
- if ( descriptor . Default is null )
414
+ try
417
415
{
418
- _logger . LogDebug ( "Request handler was not found (or not setup) {Method} {ResponseId}" , item . Request . Method , item . Request . Id ) ;
419
- _outputHandler . Send ( new MethodNotFound ( item . Request . Id , item . Request . Method ) ) ;
420
- return ;
421
- }
416
+ // _logger.LogDebug("Handling Request {Method} {ResponseId}", item.Request.Method, item.Request.Id);
417
+ var descriptor = _requestRouter . GetDescriptors ( item . Request ) ;
418
+ if ( descriptor . Default is null )
419
+ {
420
+ _logger . LogDebug ( "Request handler was not found (or not setup) {Method} {ResponseId}" , item . Request . Method , item . Request . Id ) ;
421
+ _outputHandler . Send ( new MethodNotFound ( item . Request . Id , item . Request . Method ) ) ;
422
+ return ;
423
+ }
422
424
423
- var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
424
- _scheduler . Add ( type , $ "{ item . Request . Method } :{ item . Request . Id } ", RouteRequest ( descriptor , item . Request ) ) ;
425
+ var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
426
+ _scheduler . Add ( type , $ "{ item . Request . Method } :{ item . Request . Id } ", RouteRequest ( descriptor , item . Request ) ) ;
427
+ }
428
+ catch ( JsonReaderException e )
429
+ {
430
+ _outputHandler . Send ( new ParseError ( item . Request . Id , item . Request . Method ) ) ;
431
+ _logger . LogCritical ( e , "Error parsing request" ) ;
432
+ }
433
+ catch ( Exception e )
434
+ {
435
+ _outputHandler . Send ( new InternalError ( item . Request . Id , item . Request . Method ) ) ;
436
+ _logger . LogCritical ( e , "Unknown error handling request" ) ;
437
+ }
425
438
}
426
439
427
440
if ( item . IsNotification && item . Notification != null )
428
441
{
429
- // We need to special case cancellation so that we can cancel any request that is currently in flight.
430
- if ( item . Notification . Method == JsonRpcNames . CancelRequest )
442
+ try
431
443
{
432
- _logger . LogDebug ( "Found cancellation request {Method}" , item . Notification . Method ) ;
433
- var cancelParams = item . Notification . Params ? . ToObject < CancelParams > ( ) ;
434
- if ( cancelParams == null )
444
+ // We need to special case cancellation so that we can cancel any request that is currently in flight.
445
+ if ( item . Notification . Method == JsonRpcNames . CancelRequest )
435
446
{
436
- _logger . LogDebug ( "Got incorrect cancellation params" , item . Notification . Method ) ;
447
+ _logger . LogDebug ( "Found cancellation request {Method}" , item . Notification . Method ) ;
448
+ var cancelParams = item . Notification . Params ? . ToObject < CancelParams > ( ) ;
449
+ if ( cancelParams == null )
450
+ {
451
+ _logger . LogDebug ( "Got incorrect cancellation params" , item . Notification . Method ) ;
452
+ continue ;
453
+ }
454
+
455
+ _logger . LogDebug ( "Cancelling pending request" , item . Notification . Method ) ;
456
+ if ( _requests . TryGetValue ( cancelParams . Id , out var d ) )
457
+ {
458
+ d . cancellationTokenSource . Cancel ( ) ;
459
+ }
460
+
437
461
continue ;
438
462
}
439
463
440
- _logger . LogDebug ( "Cancelling pending request" , item . Notification . Method ) ;
441
- if ( _requests . TryGetValue ( cancelParams . Id , out var d ) )
464
+ // _logger.LogDebug("Handling Request {Method}", item.Notification.Method);
465
+ var descriptor = _requestRouter . GetDescriptors ( item . Notification ) ;
466
+ if ( descriptor . Default is null )
442
467
{
443
- d . cancellationTokenSource . Cancel ( ) ;
468
+ _logger . LogDebug ( "Notification handler was not found (or not setup) {Method}" , item . Notification . Method ) ;
469
+ // TODO: Figure out a good way to send this feedback back.
470
+ // _outputHandler.Send(new RpcError(null, new ErrorMessage(-32601, $"Method not found - {item.Notification.Method}")));
471
+ return ;
444
472
}
445
473
446
- continue ;
447
- }
474
+ var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
475
+ _scheduler . Add ( type , item . Notification . Method , RouteNotification ( descriptor , item . Notification ) ) ;
448
476
449
- // _logger.LogDebug("Handling Request {Method}", item.Notification.Method);
450
- var descriptor = _requestRouter . GetDescriptors ( item . Notification ) ;
451
- if ( descriptor . Default is null )
477
+ }
478
+ catch ( JsonReaderException e )
452
479
{
453
- _logger . LogDebug ( "Notification handler was not found (or not setup) {Method}" , item . Notification . Method ) ;
454
- // TODO: Figure out a good way to send this feedback back.
455
- // _outputHandler.Send(new RpcError(null, new ErrorMessage(-32601, $"Method not found - {item.Notification.Method}")));
456
- return ;
480
+ _logger . LogCritical ( e , "Error parsing notification" ) ;
481
+ }
482
+ catch ( Exception e )
483
+ {
484
+ _logger . LogCritical ( e , "Unknown error handling notification" ) ;
457
485
}
458
-
459
- var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
460
- _scheduler . Add ( type , item . Notification . Method , RouteNotification ( descriptor , item . Notification ) ) ;
461
486
}
462
487
463
488
if ( item . IsError )
0 commit comments