From 8de357f4885046cd2573884debe146125728a148 Mon Sep 17 00:00:00 2001 From: Melvin Date: Tue, 15 Nov 2016 15:17:54 +0100 Subject: [PATCH] Ensure message format availability Make sure the entire process doesn't crash when a message is sent without `type` and/or `data` as such: ``` error: Uncaught Exception TypeError: Cannot read property 'id' of undefined at Server.gotData (/usr/src/app/node_modules/@trail/pigeoneer/node_modules/node-ipc/dao/socketServer.js:181:24) at emitOne (events.js:101:20) at Socket.emit (events.js:188:7) at Socket.EventEmitter.emit (/usr/src/app/node_modules/@trail/pigeoneer/node_modules/sc-domain/index.js:12:31) at readableAddChunk (_stream_readable.js:176:18) at Socket.Readable.push (_stream_readable.js:134:10) at TCP.onread (net.js:548:20) ``` --- dao/socketServer.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dao/socketServer.js b/dao/socketServer.js index a637979..9193c4d 100644 --- a/dao/socketServer.js +++ b/dao/socketServer.js @@ -175,7 +175,12 @@ function gotData(socket,data,UDPSocket){ while(data.length>0){ let message=new Message; message.load(data.shift()); - + + // In case either `type` or `data` is missing we won't process this message. + if (!message.type || !message.data) { + continue; + } + this.log('received event of : ',message.type,message.data); if(message.data.id){