mysql2 3.22.1 → 3.22.2-canary.c79a3f32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/promise/capture_local_err.js +25 -0
- package/lib/promise/connection.js +35 -45
- package/lib/promise/make_done_cb.js +5 -8
- package/lib/promise/pool.js +11 -11
- package/lib/promise/pool_cluster.js +9 -4
- package/lib/promise/prepared_statement_info.js +5 -2
- package/package.json +1 -1
- package/promise.js +16 -17
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** @param {Function} constructorOpt Passed to Error.captureStackTrace (omit this frame from stacks). */
|
|
4
|
+
function captureStackHolder(constructorOpt) {
|
|
5
|
+
const holder = {};
|
|
6
|
+
Error.captureStackTrace(holder, constructorOpt);
|
|
7
|
+
return holder;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Replace `err.stack` frames with the capture from `holder`, keeping the
|
|
12
|
+
* callback error instance and its MySQL fields.
|
|
13
|
+
*
|
|
14
|
+
* @param {Error} err
|
|
15
|
+
* @param {{ stack?: string }} holder
|
|
16
|
+
*/
|
|
17
|
+
function applyCapturedStack(err, holder) {
|
|
18
|
+
const stack = holder && holder.stack;
|
|
19
|
+
if (typeof stack !== 'string' || !stack) return;
|
|
20
|
+
const lines = stack.split('\n');
|
|
21
|
+
lines[0] = `${err.name}: ${err.message}`;
|
|
22
|
+
err.stack = lines.join('\n');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = { captureStackHolder, applyCapturedStack };
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events').EventEmitter;
|
|
4
4
|
const PromisePreparedStatementInfo = require('./prepared_statement_info.js');
|
|
5
|
+
const {
|
|
6
|
+
captureStackHolder,
|
|
7
|
+
applyCapturedStack,
|
|
8
|
+
} = require('./capture_local_err.js');
|
|
5
9
|
const makeDoneCb = require('./make_done_cb.js');
|
|
6
10
|
const inheritEvents = require('./inherit_events.js');
|
|
7
11
|
const BaseConnection = require('../base/connection.js');
|
|
@@ -26,14 +30,14 @@ class PromiseConnection extends EventEmitter {
|
|
|
26
30
|
|
|
27
31
|
query(query, params) {
|
|
28
32
|
const c = this.connection;
|
|
29
|
-
const
|
|
33
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.query);
|
|
30
34
|
if (typeof params === 'function') {
|
|
31
35
|
throw new Error(
|
|
32
36
|
'Callback function is not available with promise clients.'
|
|
33
37
|
);
|
|
34
38
|
}
|
|
35
39
|
return new this.Promise((resolve, reject) => {
|
|
36
|
-
const done = makeDoneCb(resolve, reject,
|
|
40
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
37
41
|
if (params !== undefined) {
|
|
38
42
|
c.query(query, params, done);
|
|
39
43
|
} else {
|
|
@@ -44,14 +48,14 @@ class PromiseConnection extends EventEmitter {
|
|
|
44
48
|
|
|
45
49
|
execute(query, params) {
|
|
46
50
|
const c = this.connection;
|
|
47
|
-
const
|
|
51
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.execute);
|
|
48
52
|
if (typeof params === 'function') {
|
|
49
53
|
throw new Error(
|
|
50
54
|
'Callback function is not available with promise clients.'
|
|
51
55
|
);
|
|
52
56
|
}
|
|
53
57
|
return new this.Promise((resolve, reject) => {
|
|
54
|
-
const done = makeDoneCb(resolve, reject,
|
|
58
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
55
59
|
if (params !== undefined) {
|
|
56
60
|
c.execute(query, params, done);
|
|
57
61
|
} else {
|
|
@@ -74,43 +78,43 @@ class PromiseConnection extends EventEmitter {
|
|
|
74
78
|
|
|
75
79
|
beginTransaction() {
|
|
76
80
|
const c = this.connection;
|
|
77
|
-
const
|
|
81
|
+
const stackHolder = captureStackHolder(
|
|
82
|
+
PromiseConnection.prototype.beginTransaction
|
|
83
|
+
);
|
|
78
84
|
return new this.Promise((resolve, reject) => {
|
|
79
|
-
const done = makeDoneCb(resolve, reject,
|
|
85
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
80
86
|
c.beginTransaction(done);
|
|
81
87
|
});
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
commit() {
|
|
85
91
|
const c = this.connection;
|
|
86
|
-
const
|
|
92
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.commit);
|
|
87
93
|
return new this.Promise((resolve, reject) => {
|
|
88
|
-
const done = makeDoneCb(resolve, reject,
|
|
94
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
89
95
|
c.commit(done);
|
|
90
96
|
});
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
rollback() {
|
|
94
100
|
const c = this.connection;
|
|
95
|
-
const
|
|
101
|
+
const stackHolder = captureStackHolder(
|
|
102
|
+
PromiseConnection.prototype.rollback
|
|
103
|
+
);
|
|
96
104
|
return new this.Promise((resolve, reject) => {
|
|
97
|
-
const done = makeDoneCb(resolve, reject,
|
|
105
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
98
106
|
c.rollback(done);
|
|
99
107
|
});
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
ping() {
|
|
103
111
|
const c = this.connection;
|
|
104
|
-
const
|
|
112
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.ping);
|
|
105
113
|
return new this.Promise((resolve, reject) => {
|
|
106
114
|
c.ping((err) => {
|
|
107
115
|
if (err) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
localErr.errno = err.errno;
|
|
111
|
-
localErr.sqlState = err.sqlState;
|
|
112
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
113
|
-
reject(localErr);
|
|
116
|
+
applyCapturedStack(err, stackHolder);
|
|
117
|
+
reject(err);
|
|
114
118
|
} else {
|
|
115
119
|
resolve(true);
|
|
116
120
|
}
|
|
@@ -120,16 +124,12 @@ class PromiseConnection extends EventEmitter {
|
|
|
120
124
|
|
|
121
125
|
reset() {
|
|
122
126
|
const c = this.connection;
|
|
123
|
-
const
|
|
127
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.reset);
|
|
124
128
|
return new this.Promise((resolve, reject) => {
|
|
125
129
|
c.reset((err) => {
|
|
126
130
|
if (err) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
localErr.errno = err.errno;
|
|
130
|
-
localErr.sqlState = err.sqlState;
|
|
131
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
132
|
-
reject(localErr);
|
|
131
|
+
applyCapturedStack(err, stackHolder);
|
|
132
|
+
reject(err);
|
|
133
133
|
} else {
|
|
134
134
|
resolve();
|
|
135
135
|
}
|
|
@@ -139,16 +139,12 @@ class PromiseConnection extends EventEmitter {
|
|
|
139
139
|
|
|
140
140
|
connect() {
|
|
141
141
|
const c = this.connection;
|
|
142
|
-
const
|
|
142
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.connect);
|
|
143
143
|
return new this.Promise((resolve, reject) => {
|
|
144
144
|
c.connect((err, param) => {
|
|
145
145
|
if (err) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
localErr.errno = err.errno;
|
|
149
|
-
localErr.sqlState = err.sqlState;
|
|
150
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
151
|
-
reject(localErr);
|
|
146
|
+
applyCapturedStack(err, stackHolder);
|
|
147
|
+
reject(err);
|
|
152
148
|
} else {
|
|
153
149
|
resolve(param);
|
|
154
150
|
}
|
|
@@ -159,16 +155,12 @@ class PromiseConnection extends EventEmitter {
|
|
|
159
155
|
prepare(options) {
|
|
160
156
|
const c = this.connection;
|
|
161
157
|
const promiseImpl = this.Promise;
|
|
162
|
-
const
|
|
158
|
+
const stackHolder = captureStackHolder(PromiseConnection.prototype.prepare);
|
|
163
159
|
return new this.Promise((resolve, reject) => {
|
|
164
160
|
c.prepare(options, (err, statement) => {
|
|
165
161
|
if (err) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
localErr.errno = err.errno;
|
|
169
|
-
localErr.sqlState = err.sqlState;
|
|
170
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
171
|
-
reject(localErr);
|
|
162
|
+
applyCapturedStack(err, stackHolder);
|
|
163
|
+
reject(err);
|
|
172
164
|
} else {
|
|
173
165
|
const wrappedStatement = new PromisePreparedStatementInfo(
|
|
174
166
|
statement,
|
|
@@ -182,16 +174,14 @@ class PromiseConnection extends EventEmitter {
|
|
|
182
174
|
|
|
183
175
|
changeUser(options) {
|
|
184
176
|
const c = this.connection;
|
|
185
|
-
const
|
|
177
|
+
const stackHolder = captureStackHolder(
|
|
178
|
+
PromiseConnection.prototype.changeUser
|
|
179
|
+
);
|
|
186
180
|
return new this.Promise((resolve, reject) => {
|
|
187
181
|
c.changeUser(options, (err) => {
|
|
188
182
|
if (err) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
localErr.errno = err.errno;
|
|
192
|
-
localErr.sqlState = err.sqlState;
|
|
193
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
194
|
-
reject(localErr);
|
|
183
|
+
applyCapturedStack(err, stackHolder);
|
|
184
|
+
reject(err);
|
|
195
185
|
} else {
|
|
196
186
|
resolve();
|
|
197
187
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const { applyCapturedStack } = require('./capture_local_err.js');
|
|
4
|
+
|
|
5
|
+
function makeDoneCb(resolve, reject, stackHolder) {
|
|
4
6
|
return function (err, rows, fields) {
|
|
5
7
|
if (err) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
localErr.errno = err.errno;
|
|
9
|
-
localErr.sql = err.sql;
|
|
10
|
-
localErr.sqlState = err.sqlState;
|
|
11
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
12
|
-
reject(localErr);
|
|
8
|
+
applyCapturedStack(err, stackHolder);
|
|
9
|
+
reject(err);
|
|
13
10
|
} else {
|
|
14
11
|
resolve([rows, fields]);
|
|
15
12
|
}
|
package/lib/promise/pool.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const EventEmitter = require('events').EventEmitter;
|
|
4
|
+
const {
|
|
5
|
+
captureStackHolder,
|
|
6
|
+
applyCapturedStack,
|
|
7
|
+
} = require('./capture_local_err.js');
|
|
4
8
|
const makeDoneCb = require('./make_done_cb.js');
|
|
5
9
|
const PromisePoolConnection = require('./pool_connection.js');
|
|
6
10
|
const inheritEvents = require('./inherit_events.js');
|
|
@@ -33,14 +37,14 @@ class PromisePool extends EventEmitter {
|
|
|
33
37
|
|
|
34
38
|
query(sql, args) {
|
|
35
39
|
const corePool = this.pool;
|
|
36
|
-
const
|
|
40
|
+
const stackHolder = captureStackHolder(PromisePool.prototype.query);
|
|
37
41
|
if (typeof args === 'function') {
|
|
38
42
|
throw new Error(
|
|
39
43
|
'Callback function is not available with promise clients.'
|
|
40
44
|
);
|
|
41
45
|
}
|
|
42
46
|
return new this.Promise((resolve, reject) => {
|
|
43
|
-
const done = makeDoneCb(resolve, reject,
|
|
47
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
44
48
|
if (args !== undefined) {
|
|
45
49
|
corePool.query(sql, args, done);
|
|
46
50
|
} else {
|
|
@@ -51,14 +55,14 @@ class PromisePool extends EventEmitter {
|
|
|
51
55
|
|
|
52
56
|
execute(sql, args) {
|
|
53
57
|
const corePool = this.pool;
|
|
54
|
-
const
|
|
58
|
+
const stackHolder = captureStackHolder(PromisePool.prototype.execute);
|
|
55
59
|
if (typeof args === 'function') {
|
|
56
60
|
throw new Error(
|
|
57
61
|
'Callback function is not available with promise clients.'
|
|
58
62
|
);
|
|
59
63
|
}
|
|
60
64
|
return new this.Promise((resolve, reject) => {
|
|
61
|
-
const done = makeDoneCb(resolve, reject,
|
|
65
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
62
66
|
if (args) {
|
|
63
67
|
corePool.execute(sql, args, done);
|
|
64
68
|
} else {
|
|
@@ -69,16 +73,12 @@ class PromisePool extends EventEmitter {
|
|
|
69
73
|
|
|
70
74
|
end() {
|
|
71
75
|
const corePool = this.pool;
|
|
72
|
-
const
|
|
76
|
+
const stackHolder = captureStackHolder(PromisePool.prototype.end);
|
|
73
77
|
return new this.Promise((resolve, reject) => {
|
|
74
78
|
corePool.end((err) => {
|
|
75
79
|
if (err) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
localErr.errno = err.errno;
|
|
79
|
-
localErr.sqlState = err.sqlState;
|
|
80
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
81
|
-
reject(localErr);
|
|
80
|
+
applyCapturedStack(err, stackHolder);
|
|
81
|
+
reject(err);
|
|
82
82
|
} else {
|
|
83
83
|
resolve();
|
|
84
84
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { captureStackHolder } = require('./capture_local_err.js');
|
|
3
4
|
const PromisePoolConnection = require('./pool_connection');
|
|
4
5
|
const makeDoneCb = require('./make_done_cb');
|
|
5
6
|
|
|
@@ -24,28 +25,32 @@ class PromisePoolNamespace {
|
|
|
24
25
|
|
|
25
26
|
query(sql, values) {
|
|
26
27
|
const corePoolNamespace = this.poolNamespace;
|
|
27
|
-
const
|
|
28
|
+
const stackHolder = captureStackHolder(
|
|
29
|
+
PromisePoolNamespace.prototype.query
|
|
30
|
+
);
|
|
28
31
|
if (typeof values === 'function') {
|
|
29
32
|
throw new Error(
|
|
30
33
|
'Callback function is not available with promise clients.'
|
|
31
34
|
);
|
|
32
35
|
}
|
|
33
36
|
return new this.Promise((resolve, reject) => {
|
|
34
|
-
const done = makeDoneCb(resolve, reject,
|
|
37
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
35
38
|
corePoolNamespace.query(sql, values, done);
|
|
36
39
|
});
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
execute(sql, values) {
|
|
40
43
|
const corePoolNamespace = this.poolNamespace;
|
|
41
|
-
const
|
|
44
|
+
const stackHolder = captureStackHolder(
|
|
45
|
+
PromisePoolNamespace.prototype.execute
|
|
46
|
+
);
|
|
42
47
|
if (typeof values === 'function') {
|
|
43
48
|
throw new Error(
|
|
44
49
|
'Callback function is not available with promise clients.'
|
|
45
50
|
);
|
|
46
51
|
}
|
|
47
52
|
return new this.Promise((resolve, reject) => {
|
|
48
|
-
const done = makeDoneCb(resolve, reject,
|
|
53
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
49
54
|
corePoolNamespace.execute(sql, values, done);
|
|
50
55
|
});
|
|
51
56
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const { captureStackHolder } = require('./capture_local_err.js');
|
|
3
4
|
const makeDoneCb = require('./make_done_cb.js');
|
|
4
5
|
|
|
5
6
|
class PromisePreparedStatementInfo {
|
|
@@ -10,9 +11,11 @@ class PromisePreparedStatementInfo {
|
|
|
10
11
|
|
|
11
12
|
execute(parameters) {
|
|
12
13
|
const s = this.statement;
|
|
13
|
-
const
|
|
14
|
+
const stackHolder = captureStackHolder(
|
|
15
|
+
PromisePreparedStatementInfo.prototype.execute
|
|
16
|
+
);
|
|
14
17
|
return new this.Promise((resolve, reject) => {
|
|
15
|
-
const done = makeDoneCb(resolve, reject,
|
|
18
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
16
19
|
if (parameters) {
|
|
17
20
|
s.execute(parameters, done);
|
|
18
21
|
} else {
|
package/package.json
CHANGED
package/promise.js
CHANGED
|
@@ -9,6 +9,10 @@ const createPool = require('./lib/create_pool.js');
|
|
|
9
9
|
const createPoolCluster = require('./lib/create_pool_cluster.js');
|
|
10
10
|
const PromiseConnection = require('./lib/promise/connection.js');
|
|
11
11
|
const PromisePool = require('./lib/promise/pool.js');
|
|
12
|
+
const {
|
|
13
|
+
captureStackHolder,
|
|
14
|
+
applyCapturedStack,
|
|
15
|
+
} = require('./lib/promise/capture_local_err.js');
|
|
12
16
|
const makeDoneCb = require('./lib/promise/make_done_cb.js');
|
|
13
17
|
const PromisePoolConnection = require('./lib/promise/pool_connection.js');
|
|
14
18
|
const inheritEvents = require('./lib/promise/inherit_events.js');
|
|
@@ -16,7 +20,7 @@ const PromisePoolNamespace = require('./lib/promise/pool_cluster');
|
|
|
16
20
|
|
|
17
21
|
function createConnectionPromise(opts) {
|
|
18
22
|
const coreConnection = createConnection(opts);
|
|
19
|
-
const
|
|
23
|
+
const stackHolder = captureStackHolder(createConnectionPromise);
|
|
20
24
|
const thePromise = opts.Promise || Promise;
|
|
21
25
|
if (!thePromise) {
|
|
22
26
|
throw new Error(
|
|
@@ -30,11 +34,8 @@ function createConnectionPromise(opts) {
|
|
|
30
34
|
resolve(new PromiseConnection(coreConnection, thePromise));
|
|
31
35
|
});
|
|
32
36
|
coreConnection.once('error', (err) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
createConnectionErr.errno = err.errno;
|
|
36
|
-
createConnectionErr.sqlState = err.sqlState;
|
|
37
|
-
reject(createConnectionErr);
|
|
37
|
+
applyCapturedStack(err, stackHolder);
|
|
38
|
+
reject(err);
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
}
|
|
@@ -83,28 +84,30 @@ class PromisePoolCluster extends EventEmitter {
|
|
|
83
84
|
|
|
84
85
|
query(sql, args) {
|
|
85
86
|
const corePoolCluster = this.poolCluster;
|
|
86
|
-
const
|
|
87
|
+
const stackHolder = captureStackHolder(PromisePoolCluster.prototype.query);
|
|
87
88
|
if (typeof args === 'function') {
|
|
88
89
|
throw new Error(
|
|
89
90
|
'Callback function is not available with promise clients.'
|
|
90
91
|
);
|
|
91
92
|
}
|
|
92
93
|
return new this.Promise((resolve, reject) => {
|
|
93
|
-
const done = makeDoneCb(resolve, reject,
|
|
94
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
94
95
|
corePoolCluster.query(sql, args, done);
|
|
95
96
|
});
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
execute(sql, args) {
|
|
99
100
|
const corePoolCluster = this.poolCluster;
|
|
100
|
-
const
|
|
101
|
+
const stackHolder = captureStackHolder(
|
|
102
|
+
PromisePoolCluster.prototype.execute
|
|
103
|
+
);
|
|
101
104
|
if (typeof args === 'function') {
|
|
102
105
|
throw new Error(
|
|
103
106
|
'Callback function is not available with promise clients.'
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
109
|
return new this.Promise((resolve, reject) => {
|
|
107
|
-
const done = makeDoneCb(resolve, reject,
|
|
110
|
+
const done = makeDoneCb(resolve, reject, stackHolder);
|
|
108
111
|
corePoolCluster.execute(sql, args, done);
|
|
109
112
|
});
|
|
110
113
|
}
|
|
@@ -118,16 +121,12 @@ class PromisePoolCluster extends EventEmitter {
|
|
|
118
121
|
|
|
119
122
|
end() {
|
|
120
123
|
const corePoolCluster = this.poolCluster;
|
|
121
|
-
const
|
|
124
|
+
const stackHolder = captureStackHolder(PromisePoolCluster.prototype.end);
|
|
122
125
|
return new this.Promise((resolve, reject) => {
|
|
123
126
|
corePoolCluster.end((err) => {
|
|
124
127
|
if (err) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
localErr.errno = err.errno;
|
|
128
|
-
localErr.sqlState = err.sqlState;
|
|
129
|
-
localErr.sqlMessage = err.sqlMessage;
|
|
130
|
-
reject(localErr);
|
|
128
|
+
applyCapturedStack(err, stackHolder);
|
|
129
|
+
reject(err);
|
|
131
130
|
} else {
|
|
132
131
|
resolve();
|
|
133
132
|
}
|