Skip to content

Commit

Permalink
- Fixed unnamed functions error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmeessen authored and cjihrig committed Nov 20, 2018
1 parent 0fc756c commit b49b01b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ exports.thrownAt = function (error) {
error = error || new Error();
const stack = typeof error.stack === 'string' ? error.stack : '';
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] || '';
const at = frame.match(/^\s*at [^(]*\(?(.+)\:(\d+)\:(\d+)\)?$/);
const at = frame.match(/^\s*at [^(/]*\(?(.+)\:(\d+)\:(\d+)\)?$/);
return Array.isArray(at) ? {
filename: at[1],
line: at[2],
Expand Down
21 changes: 21 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2424,4 +2424,25 @@ describe('thrownAt()', () => {

Hoek.assert(at === undefined, 'Reports the wrong at information');
});

it('handles error with unnamed functions', () => {

const test = (f) => f();

try {

// eslint-disable-next-line prefer-arrow-callback
test(function () {

Code.expect(true).to.be.false();
});

Code.fail('an error should have been thrown');
}
catch (ex) {

const at = Code.thrownAt(ex);
Hoek.assert(at.filename === __filename);
}
});
});

0 comments on commit b49b01b

Please sign in to comment.