Make getStack to clean up event when error occurs

This commit is contained in:
Fabian Stamm 2020-04-11 15:05:17 +02:00
parent fa7a168f17
commit f51f4e2aad

View File

@ -391,25 +391,23 @@ export function withColor(color: Colors, value: any): ColorFormat {
function getStack() {
// Save original Error.prepareStackTrace
let origPrepareStackTrace = (<any>Error).prepareStackTrace;
try {
// Override with function that just returns `stack`
(<any>Error).prepareStackTrace = function (_, stack) {
return stack;
};
// Create a new `Error`, which automatically gets `stack`
let err = new Error();
// Evaluate `err.stack`, which calls our new `Error.prepareStackTrace`
let stack: any[] = <any>err.stack;
// Override with function that just returns `stack`
(<any>Error).prepareStackTrace = function (_, stack) {
return stack;
};
// Create a new `Error`, which automatically gets `stack`
let err = new Error();
// Evaluate `err.stack`, which calls our new `Error.prepareStackTrace`
let stack: any[] = <any>err.stack;
// Restore original `Error.prepareStackTrace`
(<any>Error).prepareStackTrace = origPrepareStackTrace;
// Remove superfluous function call on stack
stack.shift(); // getStack --> Error
return stack;
} finally {
// Restore original `Error.prepareStackTrace`
(<any>Error).prepareStackTrace = origPrepareStackTrace;
}
}
function baseName(path) {