我使用longjohn使用以下代码获得错误的堆栈跟踪.它显示从第一个函数调用setTimeout,但实际上程序在firstfunction执行之前崩溃. 我在这里创了一张票 https://github.com/mattinsler/longjohn/issues/16 va
我在这里创了一张票
https://github.com/mattinsler/longjohn/issues/16
var longjohn = require("longjohn"); setTimeout(function () { throw new Error(); }, 10); setTimeout(function () { firstfunction(); }, 10000); var firstfunction = function () { setTimeout(function () { console.log("First function"); }, 10); }
堆栈跟踪
/home/jeevan/node_js/node_modules/longjohn/dist/longjohn.js:181 throw e; ^ Error at firstfunction (/home/jeevan/node_js/longjohn.js:11:11) at listOnTimeout (timers.js:110:15) --------------------------------------------- at Object.<anonymous> (/home/jeevan/node_js/longjohn.js:10:1) at Module._compile (module.js:456:26) at Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Module._load (module.js:312:12) at Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3
我的问题是可能是什么问题,如何解决它.
它也没有longjohn.我不知道为什么,但如果你给回调命名,它会更好:
setTimeout(function MyFirstTimeoutCallback() { throw new Error(); }, 10); ...
这会生成以下回溯:
/private/tmp/node_modules/longjohn/dist/longjohn.js:181 throw e; ^ Error at MyFirstTimeoutCallback (/private/tmp/lj.js:4:9) <-- much better! at listOnTimeout (timers.js:110:15) --------------------------------------------- at Object.<anonymous> (/private/tmp/lj.js:3:1) at Module._compile (module.js:456:26) at Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Module._load (module.js:312:12) at Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:901:3
编辑:看起来这个错误是在节点0.10中引入的(某处).当我用0.8.23测试时,看起来没问题:
timers.js:103 if (!process.listeners('uncaughtException').length) throw e; ^ Error at Object.<anonymous> (/private/tmp/lj.js:4:9) <-- correct at list.ontimeout (timers.js:101:19) ...
(bug report)
编辑#2:这是V8中确认的错误(请参阅链接的错误报告).