{"record":{"id":"ae3e5c02fe64bc66","repo":"gchq/CyberChef","slug":"incorrect-number-of-sets-perhaps-you-need-to-modi","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/CartesianProduct.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 {OperationError} if fewer than 2 sets\n     */\n    validateSampleNumbers(sets) {\n        if (!sets || sets.length < 2) {\n            throw new OperationError(\"Incorrect number of sets, perhaps you\" +\n                \" need to modify the sample delimiter or add more samples?\");\n        }\n    }\n\n    /**\n     * Run the product 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","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CartesianProduct.mjs#L31-L67","documentation":"Thrown by validateSampleNumbers when the parsed input yields fewer than two sets. The Cartesian product requires at least two input sets to be meaningful, so zero or one set is rejected as misconfiguration rather than computed.","triggerScenarios":"CartesianProduct.run splits the input by the sample delimiter; if the result has length 0 or 1 (only one set, or empty input), validateSampleNumbers throws. A wrong sample delimiter (one not present in the input) collapses everything into a single set.","commonSituations":"User leaves a single sample, forgets the delimiter between samples, uses a delimiter character that also appears inside the data, or passes empty input. Sample delimiter mismatch with the data format is the dominant cause.","solutions":["Confirm the sample delimiter matches how your sets are separated in the input.","Ensure at least two non-empty sets are present, separated by that delimiter.","If a delimiter char appears within set elements, choose a delimiter not present in the data.","Trim trailing delimiters that create an empty final set."],"exampleFix":"// before — single set, no delimiter → throws\n// input: \"a,b,c\"\n// after — two sets separated by the sample delimiter\n// input: \"a,b\\nc,1,2\"","handlingStrategy":"validation","validationCode":"function countSets(input, sampleDelimiter) {\n  if (!input) return 0;\n  const parts = input.split(sampleDelimiter).filter(s => s.length > 0);\n  return parts.length;\n}\n// call: if (countSets(input, delim) < 2) { /* fix input */ }","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Split input on the sample delimiter and count non-empty parts before running.","Choose a sample delimiter that does not appear inside set elements.","Ensure at least two non-empty sets are supplied.","Trim trailing delimiters that would create an empty final set."],"tags":["cartesian-product","math","input-validation","delimiters"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}