Invalid stacktrace when using longjohn in nodejs

I am using longjohn wrong stack using the following code. It shows that setTimeout receives a call from the firstfunction , but in reality the program crashes before the first function is executed.

I created a ticket here 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); } 

stacktrace

 /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 

My question is what could be the problem, how to fix it.

+4
source share
1 answer

This happens without longjohn .

I don’t know exactly why, but if you call your callbacks, it works better:

 setTimeout(function MyFirstTimeoutCallback() { throw new Error(); }, 10); ... 

This creates the following trace:

 /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 

EDIT: It looks like this error was introduced (somewhere) in Node 0.10. When I test 0.8.23, it looks fine:

 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 )

EDIT # 2: This is a confirmed bug in V8 (see bug report).

+1
source

Source: https://habr.com/ru/post/1485587/


All Articles