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, 2022 in Node-js by Vaani
• 7,070 points
492 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).

To know more about Node JS, It's recommended to join Node JS Online Course today.

answered Jun 7, 2022 by Neha
• 9,020 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, 2022 in Node-js by Vaani
• 7,070 points
728 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, 2022 in Node-js by Neha
• 9,020 points
5,625 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, 2022 in Node-js by Neha
• 9,020 points
1,073 views
0 votes
0 answers

How can i download high quality you tube video using ytdl-core package in nodejs?

my code snippet as below: const express = ...READ MORE

Aug 19, 2022 in Node-js by Neha
• 9,020 points
1,719 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
1,942 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,468 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

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

What is the role of Nodejs and Express in a MERN stack web application when GraphQL is also used?

Node.js is a JavaScript runtime environment, which ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
2,682 views
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, 2022 in Node-js by Neha
• 9,020 points
2,991 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP