diff --git a/src/core/Chef.mjs b/src/core/Chef.mjs index ab8f83de..5be10868 100755 --- a/src/core/Chef.mjs +++ b/src/core/Chef.mjs @@ -55,8 +55,15 @@ class Chef { progress = await recipe.execute(this.dish, progress); } catch (err) { log.error(err); + + let displayStr; + if ("displayStr" in err) { + displayStr = err.displayStr; + } else { + displayStr = err.toString(); + } error = { - displayStr: err.displayStr, + displayStr: displayStr, }; progress = err.progress; } diff --git a/src/core/Ingredient.mjs b/src/core/Ingredient.mjs old mode 100755 new mode 100644 index 319dfb15..0dd31707 --- a/src/core/Ingredient.mjs +++ b/src/core/Ingredient.mjs @@ -5,7 +5,8 @@ */ import Utils from "./Utils.mjs"; -import {fromHex} from "./lib/Hex.mjs"; +import { fromHex } from "./lib/Hex.mjs"; +import OperationError from "./errors/OperationError.mjs"; /** * The arguments to operations. @@ -119,7 +120,9 @@ class Ingredient { number = parseFloat(data); if (isNaN(number)) { const sample = Utils.truncate(data.toString(), 10); - throw "Invalid ingredient value. Not a number: " + sample; + throw new OperationError( + "Invalid ingredient value. Not a number: " + sample, + ); } return number; default: diff --git a/src/core/Operation.mjs b/src/core/Operation.mjs index 24739d3f..09058766 100755 --- a/src/core/Operation.mjs +++ b/src/core/Operation.mjs @@ -5,6 +5,7 @@ */ import Dish from "./Dish.mjs"; +import OperationError from "./errors/OperationError.mjs"; import Ingredient from "./Ingredient.mjs"; /** @@ -223,7 +224,11 @@ class Operation { */ set ingValues(ingValues) { ingValues.forEach((val, i) => { - this._ingList[i].value = val; + try { + this._ingList[i].value = val; + } catch (err) { + throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`); + } }); } diff --git a/src/core/Recipe.mjs b/src/core/Recipe.mjs index 7824d1e8..b4a10e03 100755 --- a/src/core/Recipe.mjs +++ b/src/core/Recipe.mjs @@ -70,11 +70,15 @@ class Recipe { if (o instanceof Operation) { return o; } else { - const op = new modules[o.module][o.name](); - op.ingValues = o.ingValues; - op.breakpoint = o.breakpoint; - op.disabled = o.disabled; - return op; + try { + const op = new modules[o.module][o.name](); + op.ingValues = o.ingValues; + op.breakpoint = o.breakpoint; + op.disabled = o.disabled; + return op; + } catch (err) { + throw new Error(`Failed to hydrate operation '${o.name}': ${err}`); + } } }); }