From 7d138dc9e64c4d6944adc442e7cb595cc0e09d45 Mon Sep 17 00:00:00 2001 From: Anthony Foster <277425+aantthony@users.noreply.github.com> Date: Mon, 3 Feb 2025 12:09:59 +1100 Subject: [PATCH] fix: add missing properties to reserve query Fixes https://github.com/porsager/postgres/pull/944 The call to connect(c, query) had no query, so for a connection failure, query.origin.replace would fail, crashing the process. --- src/connection.js | 3 +++ src/index.js | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/connection.js b/src/connection.js index 97cc97e1..3b29c136 100644 --- a/src/connection.js +++ b/src/connection.js @@ -385,6 +385,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose } function queryError(query, err) { + if (query === true) { + return; + } 'query' in err || 'parameters' in err || Object.defineProperties(err, { stack: { value: err.stack + query.origin.replace(/.*\n/, '\n'), enumerable: options.debug }, query: { value: query.string, enumerable: options.debug }, diff --git a/src/index.js b/src/index.js index 2dfd24e8..9a421aa4 100644 --- a/src/index.js +++ b/src/index.js @@ -204,9 +204,10 @@ function Postgres(a, b) { const queue = Queue() const c = open.length ? open.shift() - : await new Promise(r => { - queries.push({ reserve: r }) - closed.length && connect(closed.shift()) + : await new Promise((resolve, reject) => { + const q = { reserve: resolve, reject, origin: 'reserve() call', statement: {} }; + queries.push(q); + closed.length && connect(closed.shift(), q) }) move(c, reserved)