{"record":{"id":"d0cb8f2c941cd230","repo":"gchq/CyberChef","slug":"incorrect-number-of-sets-perhaps-you-need-to-modi-d0cb8f","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/SetIntersection.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 intersection 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.runIntersect(...sets.map(s => s.split(this.itemDelimiter)));","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/SetIntersection.mjs#L31-L67","documentation":"Thrown by Set Intersection's validateSampleNumbers() when splitting the input by the sample delimiter does not produce exactly two sets. Identical logic to Set Difference: the operation requires precisely two sets to intersect.","triggerScenarios":"Input that splits into a count other than two. Most often the sample delimiter (default '\\n\\n') does not match the input's actual set separator, collapsing everything into one set, or extra delimiters create three+.","commonSituations":"Mismatched sample delimiter vs. input format; providing only one set; trailing delimiters; newline-style differences (CR vs LF, single vs double newline).","solutions":["Provide exactly two set blocks separated by the sample delimiter (default '\\n\\n').","Change the 'Sample delimiter' argument to match the separator actually present in the input.","Eliminate trailing or duplicate delimiters."],"exampleFix":"// before: only one set\nsetIntersection.run(\"apple,banana\", [\"\\\\n\\\\n\", \",\"])\n// after: two sets\nsetIntersection.run(\"apple,banana\\\\n\\\\nbanana,cherry\", [\"\\\\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":["Provide exactly two set blocks separated by the sample delimiter.","Set the 'Sample delimiter' to the separator actually used in the input.","Watch for trailing or duplicate delimiters."],"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"}