File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -573,4 +573,34 @@ describe('PgPacketStream', function () {
573573 } )
574574 } )
575575 } )
576+
577+ describe ( 'error handling' , ( ) => {
578+ it ( 'should handle unexpected errors in handlePacket' , async ( ) => {
579+ // Create a buffer with a valid row description code (0x54) and valid length
580+ // but invalid field data that will cause a parsing error
581+ const malformedBuffer = Buffer . from ( [
582+ 0x54 , // RowDescription message code
583+ 0x00 ,
584+ 0x00 ,
585+ 0x00 ,
586+ 0x0b , // length (11 bytes)
587+ 0x00 ,
588+ 0x01 , // field count (1)
589+ 0x00 ,
590+ 0x00 ,
591+ 0x00 ,
592+ 0x00 , // invalid field data
593+ 0x00 ,
594+ 0x00 ,
595+ 0x00 ,
596+ 0x00 , // invalid field data
597+ ] )
598+
599+ const messages = await parseBuffers ( [ malformedBuffer ] )
600+ assert . strictEqual ( messages . length , 1 )
601+ assert . strictEqual ( messages [ 0 ] . name , 'error' )
602+ assert ( messages [ 0 ] instanceof Error )
603+ assert ( messages [ 0 ] . message . includes ( 'unexpected error handling packet' ) )
604+ } )
605+ } )
576606} )
You can’t perform that action at this time.
0 commit comments