Make getStack to clean up event when error occurs
This commit is contained in:
parent
fa7a168f17
commit
f51f4e2aad
32
src/base.ts
32
src/base.ts
@ -391,25 +391,23 @@ export function withColor(color: Colors, value: any): ColorFormat {
|
|||||||
function getStack() {
|
function getStack() {
|
||||||
// Save original Error.prepareStackTrace
|
// Save original Error.prepareStackTrace
|
||||||
let origPrepareStackTrace = (<any>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;
|
return stack;
|
||||||
};
|
} finally {
|
||||||
|
// Restore original `Error.prepareStackTrace`
|
||||||
// Create a new `Error`, which automatically gets `stack`
|
(<any>Error).prepareStackTrace = origPrepareStackTrace;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function baseName(path) {
|
function baseName(path) {
|
||||||
|
Loading…
Reference in New Issue
Block a user