From 3b10aca3522886c9ea0e0a7fe3194d9e4f015f0e Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 10 Dec 2021 20:09:05 +0100 Subject: [PATCH] Added chunk-check against undefined --- src/streamHandler/PacketStreamFactory.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/streamHandler/PacketStreamFactory.js b/src/streamHandler/PacketStreamFactory.js index febfb93..340b9f5 100644 --- a/src/streamHandler/PacketStreamFactory.js +++ b/src/streamHandler/PacketStreamFactory.js @@ -47,8 +47,14 @@ class PacketStreamFactory extends Transform{ } _transform(chunk, encoding, next){ - let packet = new Packet(); + if(!chunk){ + const err = "Chunk was invalid!"; + logger.error(err); + next(err); + } + let packet = new Packet(); + const lines = chunk.split("\n"); const header = lines.splice(0, 1)[0]; // Grab first line, "lines" is now the payload packet = this._handleHeader(packet, header);