Permalink
Browse files

Add try catch on zmq data parsing

  • Loading branch information...
1 parent e7e2275 commit 6966c1850df25ea415e47826b37981998ca8bd26 Bertrand Paquet committed Oct 8, 2012
Showing with 9 additions and 3 deletions.
  1. +2 −2 lib/inputs/input_tcp.js
  2. +7 −1 lib/inputs/input_zeromq.js
View
@@ -21,8 +21,8 @@ InputTcp.prototype.afterLoadConfig = function(callback) {
this.server = net.createServer(function(c) {
c.on('data', function(data) {
try {
- var parsed = JSON.parse(data);
- this.emit('data', parsed);
+ var parsed = JSON.parse(data);
+ this.emit('data', parsed);
}
catch(e) {
this.emit('data', {
@@ -27,7 +27,13 @@ InputZeroMQ.prototype.afterLoadConfig = function(callback) {
}.bind(this));
this.socket.on('message', function(data) {
- this.emit('data', JSON.parse(data));
+ try {
+ var parsed = JSON.parse(data);
+ this.emit('data', parsed);
+ }
+ catch(e) {
+ this.emit('error', 'Unable to parse data ' + data);
+ }
}.bind(this));
}

0 comments on commit 6966c18

Please sign in to comment.