From 938068703b73e719faf4d88b4567c879aed2242d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 18 Aug 2020 17:05:53 +0300 Subject: [PATCH] Catch JSON parse errors --- puppet/src/client.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/puppet/src/client.js b/puppet/src/client.js index 1350c7a..e8549a4 100644 --- a/puppet/src/client.js +++ b/puppet/src/client.js @@ -149,10 +149,15 @@ export default class Client { this.log("Ignoring line, client is stopped") return } - const req = JSON.parse(line) + let req + try { + req = JSON.parse(line) + } catch (err) { + this.log("Non-JSON request:", line) + return + } if (!req.command || !req.id) { - console.log("Invalid request, terminating", this.connID) - await this.stop() + this.log("Invalid request:", line) return } if (req.id <= this.maxCommandID) {