Skip to content

Commit b49b01b

Browse files
nickmeessencjihrig
authored andcommitted
- Fixed unnamed functions error reporting
1 parent 0fc756c commit b49b01b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ exports.thrownAt = function (error) {
523523
error = error || new Error();
524524
const stack = typeof error.stack === 'string' ? error.stack : '';
525525
const frame = stack.replace(error.toString(), '').split('\n').slice(1).filter(internals.filterLocal)[0] || '';
526-
const at = frame.match(/^\s*at [^(]*\(?(.+)\:(\d+)\:(\d+)\)?$/);
526+
const at = frame.match(/^\s*at [^(/]*\(?(.+)\:(\d+)\:(\d+)\)?$/);
527527
return Array.isArray(at) ? {
528528
filename: at[1],
529529
line: at[2],

test/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -2424,4 +2424,25 @@ describe('thrownAt()', () => {
24242424

24252425
Hoek.assert(at === undefined, 'Reports the wrong at information');
24262426
});
2427+
2428+
it('handles error with unnamed functions', () => {
2429+
2430+
const test = (f) => f();
2431+
2432+
try {
2433+
2434+
// eslint-disable-next-line prefer-arrow-callback
2435+
test(function () {
2436+
2437+
Code.expect(true).to.be.false();
2438+
});
2439+
2440+
Code.fail('an error should have been thrown');
2441+
}
2442+
catch (ex) {
2443+
2444+
const at = Code.thrownAt(ex);
2445+
Hoek.assert(at.filename === __filename);
2446+
}
2447+
});
24272448
});

0 commit comments

Comments
 (0)