gchq/CyberChef · error · OperationError
Incorrect number of sets, perhaps you need to modify the…
Error message
Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?
What it means
Thrown by Set Difference's validateSampleNumbers() when splitting the input by the sample delimiter does not yield exactly two sets. The operation computes the difference of exactly two sets, so any count other than two (zero, one, three+) is rejected.
Solutions
- Ensure the input contains exactly two set blocks separated by the sample delimiter (default '\n\n').
- Adjust the 'Sample delimiter' argument to match the actual separator in your input.
- Remove stray/trailing delimiters that create empty extra sets.
Example fix
// before: input has only one set (no sample delimiter)
setDifference.run("a,b,c", ["\\n\\n", ","])
// after: two sets separated by the sample delimiter
setDifference.run("a,b,c\\n\\nd,e,f", ["\\n\\n", ","]) Defensive patterns
Strategy: validation
Validate before calling
function validateSetInput(input, sampleDelim) {
const parts = input.split(sampleDelim);
if (parts.length !== 2) {
throw new Error(`Expected exactly 2 sets separated by the sample delimiter, got ${parts.length}.`);
}
return parts;
} Type guard
function hasTwoSets(input, sampleDelim) {
return input.split(sampleDelim).length === 2;
} Prevention
- Ensure the input contains exactly two set blocks separated by the sample delimiter.
- Adjust the 'Sample delimiter' to match the input's actual separator.
- Remove trailing delimiters that create empty sets.
When it happens
Trigger: Input containing zero or one sample-delimiter occurrences (one set), or two+ occurrences (three+ sets). The default sample delimiter is '\n\n' (literal backslash-n-backslash-n as a binaryString); if the actual input uses a different separator, the split produces a single element.
Common situations: Input uses single newlines or commas between sets while the sample delimiter expects double-newline; only one set provided; trailing delimiter producing an empty third set; the binaryString delimiter not matching literal text.
Related errors
- Incorrect number of sets, perhaps you need to modify the…
- Incorrect number of samples, perhaps you need to modify the…
- Input private key must be in hex; and should be 32 bytes
- Invalid file type.
- Invalid IV length: bytes SM4 uses an IV length of 16 bytes…
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/9fcf862937f0e10f.
Report an issue: GitHub.
Appendix: source
Thrown at src/core/operations/SetDifference.mjs:49
value: "\\n\\n"
},
{
name: "Item delimiter",
type: "binaryString",
value: ","
},
];
}
/**
* Validate input length
*
* @param {Object[]} sets
* @throws {Error} if not two sets
*/
validateSampleNumbers(sets) {
if (!sets || (sets.length !== 2)) {
throw new OperationError("Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?");
}
}
/**
* Run the difference 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);
this.validateSampleNumbers(sets);
return this.runSetDifference(...sets.map(s => s.split(this.itemDelimiter)));View on GitHub (pinned to 4290ea7539)