Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ca84d0a

Browse filesBrowse files
committed
Fix early detection of bad callback to connection.query
1 parent 1428049 commit ca84d0a
Copy full SHA for ca84d0a

File tree

Expand file treeCollapse file tree

2 files changed

+20
-17
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-17
lines changed

‎lib/Connection.js

Copy file name to clipboardExpand all lines: lib/Connection.js
+16-17Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,37 @@ Connection.createQuery = function createQuery(sql, values, callback) {
2727
return sql;
2828
}
2929

30-
var cb = wrapCallbackInDomain(null, callback);
30+
var cb = callback;
3131
var options = {};
3232

3333
if (typeof sql === 'function') {
34-
cb = wrapCallbackInDomain(null, sql);
35-
return new Query(options, cb);
36-
}
37-
38-
if (typeof sql === 'object') {
34+
cb = sql;
35+
} else if (typeof sql === 'object') {
3936
for (var prop in sql) {
4037
options[prop] = sql[prop];
4138
}
4239

4340
if (typeof values === 'function') {
44-
cb = wrapCallbackInDomain(null, values);
41+
cb = values;
4542
} else if (values !== undefined) {
4643
options.values = values;
4744
}
45+
} else {
46+
options.sql = sql;
47+
options.values = values;
4848

49-
return new Query(options, cb);
49+
if (typeof values === 'function') {
50+
cb = values;
51+
options.values = undefined;
52+
}
5053
}
5154

52-
options.sql = sql;
53-
options.values = values;
54-
55-
if (typeof values === 'function') {
56-
cb = wrapCallbackInDomain(null, values);
57-
options.values = undefined;
58-
}
55+
if (cb !== undefined) {
56+
cb = wrapCallbackInDomain(null, cb);
5957

60-
if (cb === undefined && callback !== undefined) {
61-
throw new TypeError('argument callback must be a function when provided');
58+
if (cb === undefined) {
59+
throw new TypeError('argument callback must be a function when provided');
60+
}
6261
}
6362

6463
return new Query(options, cb);

‎test/unit/query/test-args-query-bad-callback.js

Copy file name to clipboardExpand all lines: test/unit/query/test-args-query-bad-callback.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ server.listen(common.fakeServerPort, function (err) {
1111
connection.query('SELECT ?', [1], 'oops');
1212
}, /TypeError: argument callback must be a function when provided/);
1313

14+
assert.throws(function () {
15+
connection.query({ sql: 'SELECT ?' }, [1], 'oops');
16+
}, /TypeError: argument callback must be a function when provided/);
17+
1418
connection.destroy();
1519
server.destroy();
1620
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.