Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/v1/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Result {
* @param {ConnectionHolder} connectionHolder - to be notified when result is either fully consumed or error happened.
*/
constructor(streamObserver, statement, parameters, metaSupplier, connectionHolder) {
this._stack = (new Error('')).stack.substr(6); // we don't need the 'Error\n' part
this._streamObserver = streamObserver;
this._p = null;
this._statement = statement;
Expand Down Expand Up @@ -137,6 +138,9 @@ class Result {
// notify connection holder that the used connection is not needed any more because error happened
// and result can't bee consumed any further; call the original onError callback after that
self._connectionHolder.releaseConnection().then(() => {
// Error.prototype.toString() concatenates error.name and error.message nicely
// then we add the rest of the stack trace
error.stack = error.toString() + '\n' + this._stack;
onErrorOriginal.call(observer, error);
});
};
Expand Down
23 changes: 23 additions & 0 deletions test/v1/result.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,27 @@ describe('result stream', () => {
}
});
});

it('should have a stack trace that contains code outside the driver calls', done => {
// Given
const fn_a = cb => fn_b(cb);
const fn_b = cb => fn_c(cb);
const fn_c = cb => session.run('RETURN 1/0 AS x').catch(cb);

// When
fn_a(err => {
const stack = err.stack;

// Then
const contains_fn_a = /at fn_a \(.*?\/result.test.js:\d+:\d+\)/.test(stack);
const contains_fn_b = /at fn_b \(.*?\/result.test.js:\d+:\d+\)/.test(stack);
const contains_fn_c = /at fn_c \(.*?\/result.test.js:\d+:\d+\)/.test(stack);

expect(contains_fn_a).toBeTruthy();
expect(contains_fn_b).toBeTruthy();
expect(contains_fn_c).toBeTruthy();

done();
});
});
});