0

I've been working on a project, a socket server, using NodeJS, with some great help from people on this site, my project is nearing completion, but I have an error generated on my code every once in a while, and I can't seem to pin point the error down, since the error log does not give a name of a variable, function or anything related to the problem, it just throws off this message:

Exception: TypeError: Cannot read property '0' of undefined

My problem also arises from the fact that there is nothing much moving in my code unless someone is connected to it, I do have an interval that runs every 4 minutes and send an update query to my DB so the connection to the DB will stay alive (we don't want to change the mySQL server wait_timeout since we use the same DB for other projects and products that needs it that way), and a kind of a global timer also set with setInterval that execute actions being sent to it from dynamicaly created game rooms, but again, the error pops up even if simply restart the service, and leave it untouched, it will come up every 10-20 minutes or so... So far I've been using this simple code to catch errors:

process.on('uncaughtException', function(err){
    _log('Exception: ' + err+"<br>");
});

but this does not give the information I need to know how to debug and find the problem. My question is is there another way to handle these errors in a way that will return a little more information about the nature of the problem?

Thanks!

Yuval
  • 149
  • 1
  • 1
  • 11
  • 1
    possible duplicate of [Node.js doesn't display entire error message on uncaughtException, is it possible?](http://stackoverflow.com/questions/9181027/node-js-doesnt-display-entire-error-message-on-uncaughtexception-is-it-possibl) – pstenstrm May 14 '14 at 13:58
  • Note that promises are throw safe and promise libraries like Bluebird give you full stack traces. – Benjamin Gruenbaum May 17 '14 at 15:07

1 Answers1

3

The err argument holds more properties like err.message and err.stack.

pstenstrm
  • 6,339
  • 5
  • 41
  • 62
  • Thanks, that was what I was looking for, I don't know why I couldn't find it on my own, since now I'l looking for it and finding the answer everywhere... :) – Yuval May 14 '14 at 14:12
  • It's easier to find when you have the answer :). I couldn't find it mentioned in the documentation so it's easy to miss. – pstenstrm May 14 '14 at 14:44