@@ -407,23 +407,47 @@ class Client extends EventEmitter {
407407 }
408408
409409 _handleRowDescription ( msg ) {
410+ const activeQuery = this . _getActiveQuery ( )
411+ if ( activeQuery == null ) {
412+ const error = new Error ( 'Received unexpected rowDescription message from backend.' )
413+ this . _handleErrorEvent ( error )
414+ return
415+ }
410416 // delegate rowDescription to active query
411- this . _getActiveQuery ( ) . handleRowDescription ( msg )
417+ activeQuery . handleRowDescription ( msg )
412418 }
413419
414420 _handleDataRow ( msg ) {
421+ const activeQuery = this . _getActiveQuery ( )
422+ if ( activeQuery == null ) {
423+ const error = new Error ( 'Received unexpected dataRow message from backend.' )
424+ this . _handleErrorEvent ( error )
425+ return
426+ }
415427 // delegate dataRow to active query
416- this . _getActiveQuery ( ) . handleDataRow ( msg )
428+ activeQuery . handleDataRow ( msg )
417429 }
418430
419431 _handlePortalSuspended ( msg ) {
432+ const activeQuery = this . _getActiveQuery ( )
433+ if ( activeQuery == null ) {
434+ const error = new Error ( 'Received unexpected portalSuspended message from backend.' )
435+ this . _handleErrorEvent ( error )
436+ return
437+ }
420438 // delegate portalSuspended to active query
421- this . _getActiveQuery ( ) . handlePortalSuspended ( this . connection )
439+ activeQuery . handlePortalSuspended ( this . connection )
422440 }
423441
424442 _handleEmptyQuery ( msg ) {
443+ const activeQuery = this . _getActiveQuery ( )
444+ if ( activeQuery == null ) {
445+ const error = new Error ( 'Received unexpected emptyQuery message from backend.' )
446+ this . _handleErrorEvent ( error )
447+ return
448+ }
425449 // delegate emptyQuery to active query
426- this . _getActiveQuery ( ) . handleEmptyQuery ( this . connection )
450+ activeQuery . handleEmptyQuery ( this . connection )
427451 }
428452
429453 _handleCommandComplete ( msg ) {
@@ -453,11 +477,23 @@ class Client extends EventEmitter {
453477 }
454478
455479 _handleCopyInResponse ( msg ) {
456- this . _getActiveQuery ( ) . handleCopyInResponse ( this . connection )
480+ const activeQuery = this . _getActiveQuery ( )
481+ if ( activeQuery == null ) {
482+ const error = new Error ( 'Received unexpected copyInResponse message from backend.' )
483+ this . _handleErrorEvent ( error )
484+ return
485+ }
486+ activeQuery . handleCopyInResponse ( this . connection )
457487 }
458488
459489 _handleCopyData ( msg ) {
460- this . _getActiveQuery ( ) . handleCopyData ( msg , this . connection )
490+ const activeQuery = this . _getActiveQuery ( )
491+ if ( activeQuery == null ) {
492+ const error = new Error ( 'Received unexpected copyData message from backend.' )
493+ this . _handleErrorEvent ( error )
494+ return
495+ }
496+ activeQuery . handleCopyData ( msg , this . connection )
461497 }
462498
463499 _handleNotification ( msg ) {
0 commit comments