mirror of
https://github.com/gchq/CyberChef.git
synced 2026-03-27 09:11:22 -07:00
Add more helpful error for when numerical ingredient is left empty (#1540)
Some checks are pending
Master Build, Test & Deploy / main (push) Waiting to run
Some checks are pending
Master Build, Test & Deploy / main (push) Waiting to run
Co-authored-by: GCHQ Developer C85297 <95289555+C85297@users.noreply.github.com>
This commit is contained in:
parent
a1f9208221
commit
8c4a55b2b1
4 changed files with 28 additions and 9 deletions
|
|
@ -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
7
src/core/Ingredient.mjs
Executable file → Normal 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:
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue