@@ -331,7 +331,13 @@ export class JupyterKernelWebSocket {
331
331
public listenMessages ( ) {
332
332
this . ws . onmessage = ( e : IWebSocket . MessageEvent ) => {
333
333
const message = JSON . parse ( e . data . toString ( ) )
334
+
334
335
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
+
335
341
const cell = this . cells [ parentMsgId ]
336
342
if ( ! cell ) {
337
343
return
@@ -430,30 +436,30 @@ export class JupyterKernelWebSocket {
430
436
timeout ?: number
431
437
) {
432
438
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 )
435
441
436
442
// give limited time for response
437
443
let timeoutSet : number | NodeJS . Timeout
438
444
if ( timeout ) {
439
445
timeoutSet = setTimeout ( ( ) => {
440
446
// stop waiting for response
441
- delete this . idAwaiter [ msg_id ]
447
+ delete this . idAwaiter [ msgID ]
442
448
reject (
443
449
new Error (
444
- `Awaiting response to "${ code } " with id: ${ msg_id } timed out.`
450
+ `Awaiting response to "${ code } " with id: ${ msgID } timed out.`
445
451
)
446
452
)
447
453
} , timeout )
448
454
}
449
455
450
456
// 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 ) => {
453
459
// stop timeout
454
460
clearInterval ( timeoutSet as number )
455
461
// stop waiting for response
456
- delete this . idAwaiter [ msg_id ]
462
+ delete this . idAwaiter [ msgID ]
457
463
458
464
resolve ( responseData )
459
465
}
0 commit comments