Skip to content

Commit 8ebf85b

Browse files
committed
add error param when doing sync error event
1 parent 74371b0 commit 8ebf85b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

test/integration/promise-wrappers/test-async-stack.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
const code = `
22
var config = require('../../common.js').config;
33
44
var assert = require('assert');
@@ -23,23 +23,25 @@ function test() {
2323
2424
let e1, e2;
2525
26-
// TODO: investigate why connaction is still open after ENETUNREACH
26+
// TODO: investigate why connection is still open after ENETUNREACH
2727
async function test1() {
2828
e1 = new Error();
2929
const conn = await createConnection({ host: '0.42.42.42' });
3030
let [rows, fields] = conn.query('select 1 + 1');
3131
await Promise.all([conn.query('select 1+1'), conn.query('syntax error')]);
3232
}
3333
34+
/*
3435
test1().catch(err => {
3536
const stack = ErrorStackParser.parse(err);
3637
const stackExpected = ErrorStackParser.parse(e1);
3738
assert(stack[1].getLineNumber() === stackExpected[0].getLineNumber() + 1);
3839
});
40+
*/
3941
4042
async function test2() {
4143
const conn = await createConnection(config);
42-
let [rows, fields] = conn.query('select 1 + 1');
44+
let [rows, fields] = await conn.query('select 1 + 1');
4345
try {
4446
e2 = new Error();
4547
await Promise.all([conn.query('select 1+1'), conn.query('syntax error')]);
@@ -55,4 +57,27 @@ function test() {
5557
}
5658
5759
test();
58-
*/
60+
61+
`;
62+
63+
process.on('unhandledRejection', function(err) {
64+
console.log(err.stack);
65+
});
66+
67+
const vm = require('vm');
68+
69+
try {
70+
vm.runInNewContext(
71+
code,
72+
{
73+
require: require
74+
},
75+
{
76+
fileName: __filename,
77+
lineOffset: 1
78+
}
79+
);
80+
} catch (err) {
81+
// ignore sync errors (must be syntax - async/await not supported)
82+
console.log(err);
83+
}

test/integration/promise-wrappers/test-promise-wrappers.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ function testErrors() {
5151
var connResolved;
5252
var connPromise = createConnection(config);
5353

54-
console.log('=== 1', connPromise);
55-
console.log('=== 2', connPromise.end);
56-
5754
connPromise
5855
.then(function(conn) {
5956
connResolved = conn;
@@ -154,7 +151,7 @@ function testEventsConnect() {
154151
doneEventsConnect = events === 5;
155152
});
156153

157-
conn.connection.emit('error');
154+
conn.connection.emit('error', new Error());
158155
conn.connection.emit('drain');
159156
conn.connection.emit('connect');
160157
conn.connection.emit('enqueue');

0 commit comments

Comments
 (0)