From 9606da7648fb07cbf8e2031e6b52b720f3aa77d2 Mon Sep 17 00:00:00 2001 From: Cherry Date: Mon, 27 Mar 2023 18:53:59 -0400 Subject: [PATCH 1/3] Add more helpful error for when numerical ingredient is left empty --- src/core/Ingredient.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index 319dfb15..ab276fc0 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -99,8 +99,6 @@ class Ingredient { * @param {string} type - The name of the data type. */ static prepare(data, type) { - let number; - switch (type) { case "binaryString": case "binaryShortString": @@ -116,7 +114,9 @@ class Ingredient { } case "number": if (data === null) return data; - number = parseFloat(data); + if (isNaN(data)) throw "Ingredient can not be empty."; + + let number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); throw "Invalid ingredient value. Not a number: " + sample; From 6f1f1d80378a37a5d95c6ef1621539290d13651c Mon Sep 17 00:00:00 2001 From: Dex Date: Mon, 27 Mar 2023 19:24:28 -0400 Subject: [PATCH 2/3] Move back `let number;` to satisfy linter requirements --- src/core/Ingredient.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index ab276fc0..161b4b9d 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -99,6 +99,8 @@ class Ingredient { * @param {string} type - The name of the data type. */ static prepare(data, type) { + let number; + switch (type) { case "binaryString": case "binaryShortString": @@ -116,7 +118,7 @@ class Ingredient { if (data === null) return data; if (isNaN(data)) throw "Ingredient can not be empty."; - let number = parseFloat(data); + number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); throw "Invalid ingredient value. Not a number: " + sample; From 028a6c737cd52a9801a83a6ab2d250fb981dc8ba Mon Sep 17 00:00:00 2001 From: Dex Date: Mon, 27 Mar 2023 19:24:28 -0400 Subject: [PATCH 3/3] Move back `let number;` to satisfy linter requirements --- src/core/Ingredient.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs index ab276fc0..bfc619c3 100755 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -99,6 +99,8 @@ class Ingredient { * @param {string} type - The name of the data type. */ static prepare(data, type) { + let number; + switch (type) { case "binaryString": case "binaryShortString": @@ -116,7 +118,7 @@ class Ingredient { if (data === null) return data; if (isNaN(data)) throw "Ingredient can not be empty."; - let number = parseFloat(data); + number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); throw "Invalid ingredient value. Not a number: " + sample;