From a39a17b220aa483c11c673447587a42b6eaf842c Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Fri, 23 Aug 2019 23:09:59 +0200 Subject: [PATCH] Throw Error objects in inventoryImports/interfacingFunctions Change throwing of strings objcts to throw proper Error objects. --- sharedPlugins/inventoryImports/interfacingFunctions.js | 4 ++-- sharedPlugins/inventoryImports/interfacingFunctions.spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.js b/sharedPlugins/inventoryImports/interfacingFunctions.js index b5ed13ff..3f7f2903 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.js @@ -11,7 +11,7 @@ function parseJsString(string){ // since eval is unsafe, maybe use https://www.npmjs.com/package/eval-sanitizer if(string.includes("require") || string.includes(";") || string.includes("eval")){ - throw "parseJsString might have gotten something that could be a xss attempt"; + throw new Error("parseJsString might have gotten something that could be a xss attempt"); } let inventory = ""; eval("inventory = " + string); @@ -119,7 +119,7 @@ function insertItemsFromObject(confirmedItems, playerName){ // we gotta construct a string because I can't find any nice library for this if(playerName && confirmedItems){ if(typeof playerName != "string") { - throw "playerName is: '"+typeof playerName+"' instead of string!"; + throw new Error("playerName is: '"+typeof playerName+"' instead of string!"); } let itemTable = "{"; Object.keys(confirmedItems).forEach(function(name){ diff --git a/sharedPlugins/inventoryImports/interfacingFunctions.spec.js b/sharedPlugins/inventoryImports/interfacingFunctions.spec.js index e8237f71..31fa3af7 100644 --- a/sharedPlugins/inventoryImports/interfacingFunctions.spec.js +++ b/sharedPlugins/inventoryImports/interfacingFunctions.spec.js @@ -141,7 +141,7 @@ describe("inventoryImports/interfacingFunctions.js", function(){ it("Throws if player name is not a string", function(){ assert.throws(function(){ let x = functions.insertItemsFromObject(testObject, testObject); - }, "playerName is: 'object' instead of string!"); + }, Error("playerName is: 'object' instead of string!")); }); it("Returns a big factorio command as string", function(){ let x = functions.insertItemsFromObject(testObject, playerName);