sivy/node-statsd

Omitting callback may throw uncaught exception

strk opened this issue · 5 comments

strk commented

When not passing a callback to the sending functions (any), DNS errors would result in an exception being thrown like this:

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: getaddrinfo EADDRINFO
    at errnoException (dns.js:31:11)
    at Object.onanswer [as oncomplete] (dns.js:123:16)

See CartoDB/Windshaft-cartodb#180

strk commented

It looks like the way to fix this would be to install a listener for "error" on this.socket

strk commented

I confirm it works by installing an handler, and it can be done from the outside:

client = new StatsD();
client.socket.on('error', function(err) { console.log(err); });

I don't know if it'd make sense for this module to provide a default handler...

hmm, I don't think it should just be "handled" the only thing that would make sense would be to make StatsD an emitter and bubble the error emission up. Although the only problem this solves is the forced breakage of the law of demeter.

strk commented

I agree it should bubble up. It would also be nice to integrate the documentation in that case.
Actually I do see that the current documentation told me about handling the error:
https://github.com/sivy/node-statsd#errors

yeah, it's bad API design on my part for forcing the breakage of LoD ... and then blatantly documenting it. heh. If I have some time in the next week or so, I'll get this in.