gchq/CyberChef · error · OperationError

Incorrect number of sets, perhaps you need to modify the sam

Error message

Incorrect number of sets, perhaps you need to modify the sample delimiter or add more samples?

What it means

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.

Source

Thrown at src/core/operations/SetUnion.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 union 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.runUnion(...sets.map(s => s.split(this.itemDelimiter)));

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Ensure the input contains exactly two blocks separated by the sample delimiter (default is a blank line, i.e. two consecutive newlines).
  2. Verify the 'Sample delimiter' argument matches the actual separator in your input (use \n\n for blank-line separation).
  3. Trim leading/trailing delimiters that create empty extra sets.
  4. Confirm you are not passing a single combined set or more than two sets.

Example fix

// before - single block, no blank line
"a,b,c"
// after - two sets separated by a blank line (\n\n)
"a,b\n\nc,d"
Defensive patterns

Strategy: validation

Validate before calling

const sampleDelim = args[0];
const sets = input.split(sampleDelim);
if (!sets || sets.length !== 2) {
  throw new Error(`Expected exactly 2 sets separated by the sample delimiter, got ${sets ? sets.length : 0}.`);
}
// safe to call SetUnion

Type guard

// no type guard; validate the structural count before invoking
function hasTwoSets(input, sampleDelim) {
  const sets = input.split(sampleDelim);
  return Array.isArray(sets) && sets.length === 2;
}

Try / catch

try {
  chef.setUnion(input, { sampleDelimiter: "\n\n", itemDelimiter: "," });
} catch (e) {
  // OperationError surfaces as the operation's dish output, not a thrown exception,
  // but in programmatic use inspect e.message for the set-count guidance.
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/9e643a3721f8107b. Report an issue: GitHub.