Skip to content


Subversion checkout URL

You can clone with
Download ZIP


exception handling #17

Dieterbe opened this Issue · 3 comments

2 participants


I would try to implement the following exception policy in node-statsd:

  • exceptions "bubble up" into the app that uses this library
  • we don't log or print to console any errors ourself, it's the toplevel app that decides how to log/write to console.
  • we document which exceptions can be raised, and where. I'm thinking of the following issues:
  • dns resolve (exception EADDRINFO)
  • host unreachable, connection refused (these don't give any exception, but that's ok: it's a udp socket anyway)
  • any other exception that might get raised?? I surely must be missing some, because at least require('dgram').createSocket('udp4') can raise errors, and socket.send() as well.

I'm new to node.js exception handling, so any input is welcome. For now I'm just tinkering and trying to find a workable solution, but I haven't figured it out yet. cc @msiebuhr


for now, i found sort of a way to do it:
in your main app, you can leverage the fact that you have access to c.socket and just do:

c.socket.on('error', function (exception) {
   #return console.log ("error event in socket.send(): " + exception);

only problem is, node prints stacktraces and I can't find how to disable it. # edit, this seems to have magically fixed itself.
related pull request #18


it may be useful to make the client itself an event emitter, this way the user doesn't need to have the knowledge of "socket" and we can emit our own events/errors if need be.


the new version adds the ability to provide a callback to each method. the callback returns an error if the message was not sent and returns the number of bytes sent if it was. This has been documented in the readme. Any other socket exceptions are bubbled up and the user can add a listener to it if they please.

@devdazed devdazed closed this
@nbrownus nbrownus referenced this issue from a commit in betable/node-statsd
@Dieterbe Dieterbe Allow for a bit cleaner error handling
* remove logging from library, it's up to the implementing app.
* expose socket in Client.socket for listening on 'error' events

This commit should be treated as experimental, I spent some time
figuring out a good way to do things, but i'm still a node newbie.
Open for discussion @ sivy#17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.