From 1ade65f3ba7306bb6c3ae0d62db1097d1e89e272 Mon Sep 17 00:00:00 2001 From: William Horning Date: Sun, 19 May 2024 03:32:56 -0400 Subject: [PATCH] fix: reject promise if deserializeMessage throws (#413) --- src/protocol/protocol.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/protocol/protocol.ts b/src/protocol/protocol.ts index fcf039b..cb4da86 100644 --- a/src/protocol/protocol.ts +++ b/src/protocol/protocol.ts @@ -120,10 +120,14 @@ export class WireProtocol { if (!bodyBuffer) { throw new MongoDriverError("Invalid response body"); } - const reply = deserializeMessage(header, bodyBuffer); const pendingMessage = this.#pendingResponses.get(header.responseTo); this.#pendingResponses.delete(header.responseTo); - pendingMessage?.resolve(reply); + try { + const reply = deserializeMessage(header, bodyBuffer); + pendingMessage?.resolve(reply); + } catch (e) { + pendingMessage?.reject(e); + } } this.#isPendingResponse = false; }