Skip to content

Instantly share code, notes, and snippets.

@yaroschiffelers
Created July 19, 2019 17:32
Show Gist options
  • Select an option

  • Save yaroschiffelers/eda926a880afca0a64e1ea637acf917e to your computer and use it in GitHub Desktop.

Select an option

Save yaroschiffelers/eda926a880afca0a64e1ea637acf917e to your computer and use it in GitHub Desktop.
Enhance Stack Trace Method (from nodejs/node/lib/events.js)
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 ] = identicalSequenceRange(ownStack, errStack);
if (len > 0) {
ownStack.splice(off + 1, len - 2,
' [... lines matching original stack trace ...]');
}
return err.stack + sep + ownStack.join('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment