Skip to content

Commit de253bb

Browse files
committed
Fix early detection of bad callback to connection.query
1 parent b6546a0 commit de253bb

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* Fix early detection of bad callback to `connection.query`
910
* Support Node.js 12.x #2211
1011
* Support Node.js 13.x
1112
* Update `bignumber.js` to 9.0.0

lib/Connection.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,11 @@ function unwrapFromDomain(fn) {
500500
}
501501

502502
function wrapCallbackInDomain(ee, fn) {
503-
if (typeof fn !== 'function' || fn.domain) {
503+
if (typeof fn !== 'function') {
504+
return undefined;
505+
}
506+
507+
if (fn.domain) {
504508
return fn;
505509
}
506510

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var assert = require('assert');
2+
var common = require('../../common');
3+
var connection = common.createConnection({port: common.fakeServerPort});
4+
5+
var server = common.createFakeServer();
6+
7+
server.listen(common.fakeServerPort, function (err) {
8+
assert.ifError(err);
9+
10+
assert.throws(function () {
11+
connection.query('SELECT ?', [1], 'oops');
12+
}, /TypeError: argument callback must be a function when provided/);
13+
14+
connection.destroy();
15+
server.destroy();
16+
});

0 commit comments

Comments
 (0)