From 5daa492f6824f591a47394d609b5d1018760b921 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Sat, 26 Jun 2021 17:27:36 +0200 Subject: [PATCH] Emitt more useful error on parse error Rethrow parse errors with the JSON content that failed to parse for JSON content sent to Clusterio from Factorio. --- packages/lib/factorio/server.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/lib/factorio/server.js b/packages/lib/factorio/server.js index d61b49c9..5b08447a 100644 --- a/packages/lib/factorio/server.js +++ b/packages/lib/factorio/server.js @@ -605,7 +605,11 @@ class FactorioServer extends events.EventEmitter { let type = line.slice(channelEnd + 1, channelEnd + 2).toString("utf-8"); let content; if (type === "j") { - content = JSON.parse(line.slice(channelEnd + 2).toString("utf-8")); + try { + content = JSON.parse(line.slice(channelEnd + 2).toString("utf-8")); + } catch (err) { + throw new Error(`Malformed JSON to ${channel}: ${line.slice(channelEnd + 2).toString("utf-8")}`); + } } else if (type === "f") { let fileName = line.slice(channelEnd + 2).toString("utf-8");