Skip to content

Commit

Permalink
[squash] bridgear comments
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Mar 1, 2018
1 parent 9cb8461 commit 92b6be1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
11 changes: 1 addition & 10 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,13 @@ function longestSeqContainedIn(a, b) {
return [ 0, 0, 0 ];
}

function longestCommonSubsequence(a, b) {
const [ l1, i1, j1 ] = longestSeqContainedIn(a, b);
const [ l2, i2, j2 ] = longestSeqContainedIn(b, a);
if (l1 > l2)
return [ l1, j1, i1 ];
else
return [ l2, i2, j2 ];
}

function enhanceStackTrace(err, own) {
const sep = '\nEmitted \'error\' event at:\n';

const errStack = err.stack.split('\n').slice(1);
const ownStack = own.stack.split('\n').slice(1);

const [ len, off ] = longestCommonSubsequence(errStack, ownStack);
const [ len, off ] = longestSeqContainedIn(ownStack, errStack);
if (len > 0) {
ownStack.splice(off + 1, len - 1,
' [... lines matching original stack trace ...]');
Expand Down
16 changes: 16 additions & 0 deletions test/parallel/test-events-uncaught-exception-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const EventEmitter = require('events');

// Tests that the error stack where the exception was thrown is *not* appended.

process.on('uncaughtException', common.mustCall((err) => {
const lines = err.stack.split('\n');
assert.strictEqual(lines[0], 'Error');
lines.slice(1).forEach((line) => {
assert(/^ at/.test(line), `${line} has an unexpected format`);
});
}));

new EventEmitter().emit('error', new Error());

0 comments on commit 92b6be1

Please sign in to comment.