我在使用node.js( https://github.com/yortus/asyncawait )的async / await实现时遇到问题。
在文档中,它说“将包含可用的堆栈跟踪”。但它并没有对我这么做。所以我认为我做错了..但我不知道我做错了什么。
为了演示我将比较“vanilla”bluebird示例的堆栈跟踪与相应的asyncawait代码的相应堆栈跟踪(asyncawait在内部使用bluebird,所以我认为这是公平的。)
首先是没有asyncawait的蓝鸟代码:
var funcB = function() {
return Promise.resolve().then(function() {
throw new Error("some err");
})
};
var funcA = function() {
return funcB();
};
gulp.task("aa",function(cb) {
funcA().then(function() {
cb();
});
});
堆栈跟踪首先产生信息“funcA - > funcB - > exception”。没有变得更好!
Error: Error: some err
at processImmediate [as _immediateCallback] (timers.js:358:17)
From previous event:
at funcB (C:\projects\JSBuildHelper\JSBuildHelper\tmp\tsreq\app\gulpfile.js:156:30)
at funcA (C:\projects\JSBuildHelper\JSBuildHelper\tmp\tsreq\app\gulpfile.js:161:12)
at Gulp.<anonymous> (C:\projects\JSBuildHelper\JSBuildHelper\tmp\tsreq\app\gulpfile.js:164:5)
at module.exports (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
at C:\Users\alex\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at process._tickCallback (node.js:355:11)
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
现在对应的asyncawait代码:
var funcB = async(function() {
throw new Error("some err");
});
var funcA = async(function () {
await(funcB());
});
gulp.task("aa", function(cb) {
funcA().then(function() {
cb();
});
});
在堆栈跟踪中,我只看到异常。没有“funcA”,没有“funcB”。
对于这个简单的程序,这就足够了。 但是我不能将它用于其他更复杂的东西,考虑到堆栈实际上有多重要。
Possibly unhandled Error: Error: some err
at catchBlock (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\src\async\fiberManager.js:51:25)
at runInFiber (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\src\async\fiberManager.js:29:9)
From previous event:
at new Promise (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\node_modules\bluebird\js\main\promise.js:84:37)
at defer (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\src\async\defer.js:6:19)
at nonIterable (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\src\async\makeAsyncFunc.js:86:28)
at f0 (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\asyncawait\src\async\makeAsyncFunc.js:119:23)
at Gulp.<anonymous> (C:\projects\JSBuildHelper\JSBuildHelper\tmp\tsreq\app\gulpfile.js:162:5)
at module.exports (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (C:\projects\JSBuildHelper\JSBuildHelper\node_modules\gulp\node_modules\orchestrator\index.js:134:8)
at C:\Users\alex\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at Function.Module.runMain (module.js:503:11)
at startup (node.js:129:16)
at node.js:814:3
我做错了还是这个限制我无法删除?