Reputation: 1059
I am new to nodejs (async) debugging. I would appreciate some help regarding error messages -
var l, m, opiton= {};
// option has actually been mis-spelt here as opiton
.....
// some more code
option.name= "new name";
Now, at the point of assignment: option.name= "new name";
nodejs server freezes without any indication, that it has encountered an error.
It would be great if nodejs could "auto generate" an error message, and say -
undefined object "option" in line 5178
or something similar.
Figuring out that option
was actually mis-spelt as opiton
takes a lot of time, especially in a large code base, with multiple callbacks per request. And it would be great, if that time can be saved.
Question - Is there a generic solution for locating run-time errors in nodejs servers?
(In a large server code base, adding a ton of logging is useful for running analytics in production environment, but not the most optimum solution for a test environment)
Upvotes: 0
Views: 28
Reputation: 30675
You can set an uncaught error handler:
process.on('uncaughtException', function (err) {
console.log('UncaughtException: message: ' + err.message);
console.log('UncaughtException: stack: ' + err.stack);
});
I would be very hesitant to use this pattern in production code since at this point the program is in an unknown state. It's best to exit at this point and (potentially) restart.
Upvotes: 1