{"record":{"id":"9e643a3721f8107b","repo":"gchq/CyberChef","slug":"incorrect-number-of-sets-perhaps-you-need-to-modi-9e643a","errorCode":null,"errorMessage":"Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?","messagePattern":"Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples\\?","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/SetUnion.mjs","lineNumber":49,"sourceCode":"                value: \"\\\\n\\\\n\"\n            },\n            {\n                name: \"Item delimiter\",\n                type: \"binaryString\",\n                value: \",\"\n            },\n        ];\n    }\n\n    /**\n     * Validate input length\n     *\n     * @param {Object[]} sets\n     * @throws {Error} if not two sets\n     */\n    validateSampleNumbers(sets) {\n        if (!sets || (sets.length !== 2)) {\n            throw new OperationError(\"Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?\");\n        }\n    }\n\n    /**\n     * Run the union operation\n     *\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     * @throws {OperationError}\n     */\n    run(input, args) {\n        [this.sampleDelim, this.itemDelimiter] = args;\n        const sets = input.split(this.sampleDelim);\n\n        this.validateSampleNumbers(sets);\n\n        return this.runUnion(...sets.map(s => s.split(this.itemDelimiter)));","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/SetUnion.mjs#L31-L67","documentation":"Thrown by SetUnion.validateSampleNumbers when the input string, split on the configured sample delimiter, does not yield exactly two sets. The operation computes the union of exactly two sets, so any other count (zero, one, or three+) is rejected before the union logic runs. The error is an OperationError, so recipe execution treats it as normal user-facing output rather than a crash.","triggerScenarios":"input.split(sampleDelim) returns a length other than 2. Happens when the input has no sample-delimiter occurrence (one set), more than one occurrence (>2 sets), a leading/trailing delimiter creating empty sets, or the delimiter does not match what the input actually uses (e.g. default '\\n\\n' vs single newlines).","commonSituations":"Paste-separated records that use a single newline instead of a blank line between sets; delimiter set to a literal '\\n\\n' string in the UI instead of an actual blank line; CSV-style input where the item delimiter and sample delimiter get swapped; empty input.","solutions":["Ensure the input contains exactly two blocks separated by the sample delimiter (default is a blank line, i.e. two consecutive newlines).","Verify the 'Sample delimiter' argument matches the actual separator in your input (use \\n\\n for blank-line separation).","Trim leading/trailing delimiters that create empty extra sets.","Confirm you are not passing a single combined set or more than two sets."],"exampleFix":"// before - single block, no blank line\n\"a,b,c\"\n// after - two sets separated by a blank line (\\n\\n)\n\"a,b\\n\\nc,d\"","handlingStrategy":"validation","validationCode":"const sampleDelim = args[0];\nconst sets = input.split(sampleDelim);\nif (!sets || sets.length !== 2) {\n  throw new Error(`Expected exactly 2 sets separated by the sample delimiter, got ${sets ? sets.length : 0}.`);\n}\n// safe to call SetUnion","typeGuard":"// no type guard; validate the structural count before invoking\nfunction hasTwoSets(input, sampleDelim) {\n  const sets = input.split(sampleDelim);\n  return Array.isArray(sets) && sets.length === 2;\n}","tryCatchPattern":"try {\n  chef.setUnion(input, { sampleDelimiter: \"\\n\\n\", itemDelimiter: \",\" });\n} catch (e) {\n  // OperationError surfaces as the operation's dish output, not a thrown exception,\n  // but in programmatic use inspect e.message for the set-count guidance.\n}","preventionTips":["Pre-split your input into exactly two blocks separated by a blank line.","Confirm the sample delimiter matches the real separator before running.","Trim input to remove stray delimiters that inflate the set count."],"tags":["set-operations","input-validation","delimiter"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}