From 7ad4468ebc8e65517c6c14a1a5b194bb81b24fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sebastian=20kr=C3=A4mer?= Date: Mon, 10 Nov 2025 12:22:37 +0100 Subject: [PATCH 1/5] Add error handling for non-function callback catch callback not a function earlier to get a proper callstack. later when executing the callback the stack may be wrong/insufficient. --- packages/pg/lib/client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index 903db6c66..c8c0aba1b 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -588,6 +588,10 @@ class Client extends EventEmitter { Error.captureStackTrace(err) throw err }) + } else { + if(!(typeof values === 'function')){ + throw new Error('callback is not a function') + } } } From 5aa5d05301e4d55baa48edc4badbcac194888dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sebastian=20kr=C3=A4mer?= Date: Mon, 10 Nov 2025 12:54:42 +0000 Subject: [PATCH 2/5] fix: lint --- packages/pg/lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index c8c0aba1b..bfabac7ca 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -589,7 +589,7 @@ class Client extends EventEmitter { throw err }) } else { - if(!(typeof values === 'function')){ + if( !(typeof values === 'function') ){ throw new Error('callback is not a function') } } From f41265c980eb3805f35f29687fcc7040401c9bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sebastian=20kr=C3=A4mer?= Date: Mon, 10 Nov 2025 13:01:57 +0000 Subject: [PATCH 3/5] fix: lint --- packages/pg/lib/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index bfabac7ca..d5cb3b365 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -589,7 +589,7 @@ class Client extends EventEmitter { throw err }) } else { - if( !(typeof values === 'function') ){ + if (!(typeof values === 'function')) { throw new Error('callback is not a function') } } From d514dd88da6e582c9f41739c9bb657c5636836c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sebastian=20kr=C3=A4mer?= Date: Mon, 10 Nov 2025 18:37:49 +0000 Subject: [PATCH 4/5] fix: test --- packages/pg-pool/index.js | 2 +- packages/pg/lib/client.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pg-pool/index.js b/packages/pg-pool/index.js index 3e505f797..a0a5990f5 100644 --- a/packages/pg-pool/index.js +++ b/packages/pg-pool/index.js @@ -402,7 +402,7 @@ class Pool extends EventEmitter { return response.result } - // allow plain text query without values + // allow plain text query without values, but callback if (typeof values === 'function') { cb = values values = undefined diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index d5cb3b365..23769c76e 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -589,7 +589,7 @@ class Client extends EventEmitter { throw err }) } else { - if (!(typeof values === 'function')) { + if (!(typeof query.callback === 'function')) { throw new Error('callback is not a function') } } From dd76bf7b550c8d64235d62df087d10a4b34583b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sebastian=20kr=C3=A4mer?= Date: Tue, 11 Nov 2025 06:32:22 +0000 Subject: [PATCH 5/5] feat: add test for new error --- packages/pg/test/unit/client/simple-query-tests.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/pg/test/unit/client/simple-query-tests.js b/packages/pg/test/unit/client/simple-query-tests.js index d7d938992..6c20c576b 100644 --- a/packages/pg/test/unit/client/simple-query-tests.js +++ b/packages/pg/test/unit/client/simple-query-tests.js @@ -140,5 +140,17 @@ test('executing query', function () { ) } }) + + test('throws an error when callback is not a function', function () { + try { + client.query('SELECT $1', [1], 'notafunction') + } catch (error) { + assert.equal( + error.message, + 'callback is not a function', + 'Should have thrown an Error for non function callback' + ) + } + }) }) })