@@ -386,6 +386,61 @@ namespace ts.server {
386386 } ) ;
387387 } ) ;
388388
389+ describe ( "exceptions" , ( ) => {
390+ const command = "testhandler" ;
391+ class TestSession extends Session {
392+ lastSent : protocol . Message ;
393+ private exceptionRaisingHandler ( _request : protocol . Request ) : { response ?: any , responseRequired : boolean } {
394+ f1 ( ) ;
395+ return ;
396+ function f1 ( ) {
397+ throw new Error ( "myMessage" ) ;
398+ }
399+ }
400+
401+ constructor ( ) {
402+ super ( {
403+ host : mockHost ,
404+ cancellationToken : nullCancellationToken ,
405+ useSingleInferredProject : false ,
406+ useInferredProjectPerProjectRoot : false ,
407+ typingsInstaller : undefined ,
408+ byteLength : Utils . byteLength ,
409+ hrtime : process . hrtime ,
410+ logger : projectSystem . nullLogger ,
411+ canUseEvents : true
412+ } ) ;
413+ this . addProtocolHandler ( command , this . exceptionRaisingHandler ) ;
414+ }
415+ send ( msg : protocol . Message ) {
416+ this . lastSent = msg ;
417+ }
418+ }
419+
420+ it ( "raised in a protocol handler generate an event" , ( ) => {
421+
422+ const session = new TestSession ( ) ;
423+
424+ const request = {
425+ command,
426+ seq : 0 ,
427+ type : "request"
428+ } ;
429+
430+ session . onMessage ( JSON . stringify ( request ) ) ;
431+ const lastSent = session . lastSent as protocol . Response ;
432+
433+ expect ( lastSent ) . to . contain ( {
434+ seq : 0 ,
435+ type : "response" ,
436+ command,
437+ success : false
438+ } ) ;
439+
440+ expect ( lastSent . message ) . has . string ( "myMessage" ) . and . has . string ( "f1" ) ;
441+ } ) ;
442+ } ) ;
443+
389444 describe ( "how Session is extendable via subclassing" , ( ) => {
390445 class TestSession extends Session {
391446 lastSent : protocol . Message ;
0 commit comments