mirror of
https://github.com/gchq/CyberChef
synced 2025-12-23 11:43:39 +00:00
Add OperationError error type and use for errors to be printed to the output panel
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* Set cartesian product operation
|
||||
@@ -44,7 +45,8 @@ class CartesianProduct extends Operation {
|
||||
*/
|
||||
validateSampleNumbers(sets) {
|
||||
if (!sets || sets.length < 2) {
|
||||
throw "Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?";
|
||||
throw new OperationError("Incorrect number of sets, perhaps you" +
|
||||
" need to modify the sample delimiter or add more samples?");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,16 +56,13 @@ class CartesianProduct extends Operation {
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
* @throws {OperationError}
|
||||
*/
|
||||
run(input, args) {
|
||||
[this.sampleDelim, this.itemDelimiter] = args;
|
||||
const sets = input.split(this.sampleDelim);
|
||||
|
||||
try {
|
||||
this.validateSampleNumbers(sets);
|
||||
} catch (e) {
|
||||
return e;
|
||||
}
|
||||
this.validateSampleNumbers(sets);
|
||||
|
||||
return this.runCartesianProduct(...sets.map(s => s.split(this.itemDelimiter)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user