Add more helpful error for when numerical ingredient is left empty (#1540)

Co-authored-by: GCHQ Developer C85297 <95289555+C85297@users.noreply.github.com>
This commit is contained in:
Cherry
2026-03-20 13:03:45 -04:00
committed by GitHub
parent a1f9208221
commit 8c4a55b2b1
4 changed files with 28 additions and 9 deletions

View File

@@ -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;
}

7
src/core/Ingredient.mjs Executable file → Normal file
View File

@@ -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:

View File

@@ -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}`);
}
});
}

View File

@@ -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}`);
}
}
});
}