Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

exception handling #17

Closed
Dieterbe opened this issue Jun 14, 2012 · 3 comments
Closed

exception handling #17

Dieterbe opened this issue Jun 14, 2012 · 3 comments

Comments

@Dieterbe
Copy link
Collaborator

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

@Dieterbe
Copy link
Collaborator Author

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);
   return;
});

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

@devdazed
Copy link
Collaborator

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.

@devdazed
Copy link
Collaborator

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.

nbrownus pushed a commit to betable/node-statsd that referenced this issue Sep 3, 2014
* 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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants