Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[squash] bridgear comments
  • Loading branch information
addaleax committed Mar 1, 2018
commit 92b6be15e78f8c6779ec95c500cb916c0f45b7d5
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());