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.
This commit is contained in:
Hornwitser committed 2021-06-26 17:59:48 +02:00
1 parent b43a181bf4
commit 5daa492f68
1 file changed
+5 -1
+5 -1
View File
@@ -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");