{"record":{"id":"9fcf862937f0e10f","repo":"gchq/CyberChef","slug":"incorrect-number-of-sets-perhaps-you-need-to-modi-9fcf86","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/SetDifference.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 difference 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.runSetDifference(...sets.map(s => s.split(this.itemDelimiter)));","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/SetDifference.mjs#L31-L67","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: input has only one set (no sample delimiter)\nsetDifference.run(\"a,b,c\", [\"\\\\n\\\\n\", \",\"])\n// after: two sets separated by the sample delimiter\nsetDifference.run(\"a,b,c\\\\n\\\\nd,e,f\", [\"\\\\n\\\\n\", \",\"])","handlingStrategy":"validation","validationCode":"function validateSetInput(input, sampleDelim) {\n  const parts = input.split(sampleDelim);\n  if (parts.length !== 2) {\n    throw new Error(`Expected exactly 2 sets separated by the sample delimiter, got ${parts.length}.`);\n  }\n  return parts;\n}","typeGuard":"function hasTwoSets(input, sampleDelim) {\n  return input.split(sampleDelim).length === 2;\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["set","data","delimiter","operation","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}