Wrong stacktrace when using longjohn in nodejs

0 votes

With the following code, I get an incorrect stacktrace while using longjohn. It appears that setTimeout is called from the firstfunction, but in reality, the application crashes before the firstfunction is invoked.

https://github.com/mattinsler/longjohn/issues/16 I've submitted a ticket about that.

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, and how can it be resolved?

Jun 7 in Node-js by Vaani
• 7,020 points
14 views

1 answer to this question.

0 votes

It happens without longjohn, too.

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

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

This generates the following traceback:

/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: looks like this bug was introduced (somewhere) in Node 0.10. When I test with 0.8.23, it looks okay:

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: it's a confirmed bug in V8 (see the linked bug report).

answered Jun 7 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
0 answers

Issue in blob storage to fileShare big file transfer : Using fileRange (nodejs Cloud function)

To file a problem with blob storage ...READ MORE

Jun 13 in Node-js by Vaani
• 7,020 points
22 views
0 votes
1 answer

How to set different destinations in nodejs using multer?

With multer 1.2.1. You need to use DiskStorage to specify where & how of the ...READ MORE

answered Jun 13 in Node-js by Neha
• 8,560 points
34 views
0 votes
1 answer

Auto deduct the payment from account using razorpay in nodejs

To interface with Razorpay APIs, install the ...READ MORE

answered Jun 14 in Node-js by Neha
• 8,560 points
13 views
0 votes
1 answer

How do I “include” functions from my other files in nodejs?

Hello @kartik, You require any js file,so you just ...READ MORE

answered Jul 9, 2020 in Node-js by Niroj
• 82,720 points
1,496 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
971 views
0 votes
1 answer
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,440 points
625 views
0 votes
1 answer
0 votes
1 answer

Fill Data In Existing PDF Form Using NodeJS

Check out the following modules on npm: fill-pdf pdffiller pdf-fill-form node-pdffiller pdfkit The node-pdffilleris ...READ MORE

answered Jun 10 in Node-js by Neha
• 8,560 points
28 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP