@@ -411,53 +411,78 @@ private void HandleRequest(in ReadOnlySequence<byte> request)
411411 {
412412 if ( item . IsRequest && item . Request != null )
413413 {
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
417415 {
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+ }
422424
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+ }
425438 }
426439
427440 if ( item . IsNotification && item . Notification != null )
428441 {
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
431443 {
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 )
435446 {
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+
437461 continue ;
438462 }
439463
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 )
442467 {
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 ;
444472 }
445473
446- continue ;
447- }
474+ var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
475+ _scheduler . Add ( type , item . Notification . Method , RouteNotification ( descriptor , item . Notification ) ) ;
448476
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 )
452479 {
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" ) ;
457485 }
458-
459- var type = _requestProcessIdentifier . Identify ( descriptor . Default ) ;
460- _scheduler . Add ( type , item . Notification . Method , RouteNotification ( descriptor , item . Notification ) ) ;
461486 }
462487
463488 if ( item . IsError )
0 commit comments