Skip to content

Commit 0089a69

Browse files
committed
chore: add test for parsing error handling
1 parent c2a168f commit 0089a69

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: packages/pg-protocol/src/inbound-parser.test.ts

+30
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)