我希望在TypeScript中能够使用堆栈跟踪。但我似乎只能看到最底部的函数名称。我正在使用Windows 10(1803)上的Node.js v12.4.0。
以下是代码:
async function thrower() {
throw new Error("test");
}
async function level1() {
return await thrower();
}
async function level2() {
return await level1();
}
async function level3() {
return await level2();
}
async function main() {
try {
await level3();
} catch(err) {
console.warn("main error", err);
}
}
console.log("node version", process.version);
main().then(() => {
console.log("all done " + __filename);
}).catch((err) => {
console.error("Something went wrong in here :(", __filename, err);
})
导致的堆栈跟踪没有提到 level1
,level2
或 level3
:
ts-node test-stack.ts
node version v12.4.0
main error Error: test
at D:\dev\server\test-stack.ts:2:9
at step (D:\dev\server\test-stack.ts:31:23)
at Object.next (D:\dev\server\test-stack.ts:12:53)
at D:\dev\server\test-stack.ts:6:71
at new Promise (<anonymous>)
at __awaiter (D:\dev\server\test-stack.ts:2:12)
at thrower (D:\dev\server\test-stack.ts:37:12)
at D:\dev\server\test-stack.ts:6:16
at step (D:\dev\server\test-stack.ts:31:23)
at Object.next (D:\dev\server\test-stack.ts:12:53)
all done D:\dev\server\test-stack.ts