Skip to content

Commit ca165e9

Browse files
committed
Capture the error stack
1 parent 3199498 commit ca165e9

File tree

5 files changed

+101
-2
lines changed

5 files changed

+101
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
**This release is under development and information may be incomplete**
66

7+
- Added code to capture the error stack. PR#1467 (Slawomir Osoba)
8+
79
- Added code to keep the method name in internally bound functions.
810
PR #1466 (Slawomir Osoba)
911

lib/util.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved
1+
// Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved
22

33
//-----------------------------------------------------------------------------
44
//
@@ -175,7 +175,10 @@ function callbackify(func) {
175175
// if last argument is not a function, simply invoke the function as usual
176176
// and a promise will be returned
177177
if (typeof arguments[arguments.length - 1] !== 'function') {
178-
return func.apply(this, arguments);
178+
return func.apply(this, arguments).catch(function stackCapture(e) {
179+
Error.captureStackTrace(e, stackCapture);
180+
throw e;
181+
});
179182
}
180183

181184
// otherwise, resolve or reject the promise and invoke the callback

test/asyncStack.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright (c) 2022, Oracle and/or its affiliates. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* 263. asyncStack.js
20+
*
21+
* DESCRIPTION
22+
* Test keeping a stacktrace in asynchronous methods.
23+
*
24+
*****************************************************************************/
25+
'use strict';
26+
27+
const oracledb = require('oracledb');
28+
const assert = require('assert');
29+
30+
31+
32+
const asyncMiddleware = async () => {
33+
await oracledb.getConnection({connectString: 'doesnotexist.oracle.com'});
34+
};
35+
36+
describe('263. asyncStack.js', () => {
37+
38+
it('263.1 stack on error in getConnection', async () => {
39+
try {
40+
await asyncMiddleware();
41+
} catch (e) {
42+
assert.strictEqual(e.errorNum, 12154); // TNS:could not resolve the connect identifier specified
43+
assert.ok(e.stack.includes('asyncStack.js:33:'), e.stack);
44+
assert.ok(e.stack.includes('asyncStack.js:40:'), e.stack);
45+
}
46+
});
47+
48+
it('263.2 stack on error in createPool', async () => {
49+
let pool = null;
50+
const dbconfig = {
51+
user : "asterix",
52+
password : "oblix",
53+
connectString : 'doesnotexist.oracle.com',
54+
poolMin : 1,
55+
poolMax : 50,
56+
poolIncrement : 5
57+
};
58+
59+
try {
60+
pool = await oracledb.createPool(dbconfig);
61+
} catch (e) {
62+
assert.strictEqual(e.errorNum, 12154);
63+
assert.ok(e.stack.includes('asyncStack.js:60:'), e.stack);
64+
} finally {
65+
if (pool) {
66+
await pool.close ();
67+
}
68+
}
69+
70+
});
71+
72+
it('263.3 stack on error in execute', async () => {
73+
const dbconfig = {
74+
user : process.env.NODE_ORACLEDB_USER,
75+
password : process.env.NODE_ORACLEDB_PASSWORD,
76+
connectString : process.env.NODE_ORACLEDB_CONNECTIONSTRING
77+
};
78+
79+
try {
80+
const conn = await oracledb.getConnection(dbconfig);
81+
await conn.execute("SELECT * FROM NON_EXISTENT_TABLE");
82+
} catch (e) {
83+
assert.strictEqual(e.errorNum, 942);
84+
assert.ok(e.stack.includes('asyncStack.js:81:'), e.stack);
85+
}
86+
87+
});
88+
89+
});

test/list.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5300,6 +5300,10 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
53005300
262. dbObjectOutBind.js
53015301
262.1 call procedure with 2 OUT binds of DbObject
53025302

5303+
263. asyncStack.js
5304+
263.1 stack on error in getConnection
5305+
263.2 stack on error in createPool
5306+
263.3 stack on error in execute
53035307

53045308
264. methodName.js
53055309
264.1 check for methodName getConnection

test/opts/.mocharc.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,5 @@ spec:
249249
- test/tpcResume.js
250250
- test/connHealthy.js
251251
- test/dbObjectOutBind.js
252+
- test/asyncStack.js
252253
- test/methodName.js

0 commit comments

Comments
 (0)