@@ -331,7 +331,13 @@ export class JupyterKernelWebSocket {
331331 public listenMessages ( ) {
332332 this . ws . onmessage = ( e : IWebSocket . MessageEvent ) => {
333333 const message = JSON . parse ( e . data . toString ( ) )
334+
334335 const parentMsgId = message . parent_header . msg_id
336+ if ( parentMsgId == undefined ) {
337+ console . warn ( `Parent message ID not found.\n Message: ${ message } ` )
338+ return
339+ }
340+
335341 const cell = this . cells [ parentMsgId ]
336342 if ( ! cell ) {
337343 return
@@ -430,30 +436,30 @@ export class JupyterKernelWebSocket {
430436 timeout ?: number
431437 ) {
432438 return new Promise < Execution > ( ( resolve , reject ) => {
433- const msg_id = id ( 16 )
434- const data = this . sendExecuteRequest ( msg_id , code )
439+ const msgID = id ( 16 )
440+ const data = this . sendExecuteRequest ( msgID , code )
435441
436442 // give limited time for response
437443 let timeoutSet : number | NodeJS . Timeout
438444 if ( timeout ) {
439445 timeoutSet = setTimeout ( ( ) => {
440446 // stop waiting for response
441- delete this . idAwaiter [ msg_id ]
447+ delete this . idAwaiter [ msgID ]
442448 reject (
443449 new Error (
444- `Awaiting response to "${ code } " with id: ${ msg_id } timed out.`
450+ `Awaiting response to "${ code } " with id: ${ msgID } timed out.`
445451 )
446452 )
447453 } , timeout )
448454 }
449455
450456 // expect response
451- this . cells [ msg_id ] = new CellExecution ( onStdout , onStderr , onResult )
452- this . idAwaiter [ msg_id ] = ( responseData : Execution ) => {
457+ this . cells [ msgID ] = new CellExecution ( onStdout , onStderr , onResult )
458+ this . idAwaiter [ msgID ] = ( responseData : Execution ) => {
453459 // stop timeout
454460 clearInterval ( timeoutSet as number )
455461 // stop waiting for response
456- delete this . idAwaiter [ msg_id ]
462+ delete this . idAwaiter [ msgID ]
457463
458464 resolve ( responseData )
459465 }
0 commit comments