gchq/CyberChef · error · OperationError

Switch R${qr+1}-Q${a+1} can only be set to blank, . or x

Error message

Switch R${qr+1}-Q${a+1} can only be set to blank, . or x

What it means

Thrown during Colossus Q-switch validation: each of the 15 conditional R1–R3 / Q1–Q5 switches must be blank, '.', or 'x'. The regex ^$|^[.x]$ is tested against args[9]..args[29] (stepping 7 per row, 5 per row); any other value names the offending switch (R{qr+1}-Q{a+1}).

Source

Thrown at src/core/operations/Colossus.mjs:400

        if (limitation.includes("Χ2")) lm[0] = true;
        if (limitation.includes("Ψ1")) lm[1] = true;
        if (limitation.includes("P5")) lm[2] = true;
        const limit = {
            X2: lm[0], S1: lm[1], P5: lm[2]
        };

        const KRackOpt = args[6];
        const setProgram = args[7];

        if (KRackOpt === "Select Program" && setProgram !== "") {
            args = this.selectProgram(setProgram, args);
        }

        const re = new RegExp("^$|^[.x]$");
        for (let qr=0;qr<3;qr++) {
            for (let a=0;a<5;a++) {
                if (!re.test(args[((qr*7)+(a+9))]))
                    throw new OperationError("Switch R"+(qr+1)+"-Q"+(a+1)+" can only be set to blank, . or x");
            }
        }

        if (!re.test(args[37])) throw new OperationError("Switch Add-Equals can only be set to blank, . or x");
        if (!re.test(args[40])) throw new OperationError("Switch Total Motor can only be set to blank, . or x");

        // Q1,Q2,Q3,Q4,Q5,negate,counter1
        const qbusswitches = {
            condition: [
                {Qswitches: [args[9], args[10], args[11], args[12], args[13]], Negate: args[14], Counter: args[15]},
                {Qswitches: [args[16], args[17], args[18], args[19], args[20]], Negate: args[21], Counter: args[22]},
                {Qswitches: [args[23], args[24], args[25], args[26], args[27]], Negate: args[28], Counter: args[29]}
            ],
            condNegateAll: args[30],
            addition: [
                {Qswitches: [args[32], args[33], args[34], args[35], args[36]], Equals: args[37], C1: args[38]}
            ],
            addNegateAll: args[39],

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Set each R/Q switch to exactly '', '.', or 'x' (lowercase x).
  2. If using 'Select Program', ensure selectProgram returns clean values; otherwise clear and set switches manually.
  3. Normalize values: uppercase 'X' → 'x', '1'/'0' → 'x'/'.'.
  4. Validate the 15 cells before running.

Example fix

// before
// args[9] = "X"  // uppercase → throws
// after
// args[9] = "x"
Defensive patterns

Strategy: validation

Validate before calling

const SWITCH_RE = /^$|^[.x]$/;
for (let qr=0; qr<3; qr++) {
  for (let a=0; a<5; a++) {
    if (!SWITCH_RE.test(args[(qr*7)+(a+9)])) { /* fix args before run */ }
  }
}

Type guard

function isValidSwitch(v) { return /^$|^[.x]$/.test(v); }

Try / catch

null

Prevention

When it happens

Trigger: Colossus.run iterates qr=0..2 and a=0..4 testing args[(qr*7)+(a+9)]. A value other than '', '.', or 'x' (e.g. 'X' uppercase, '1', 'Y', null) throws 'Switch R{n}-Q{m} can only be set to blank, . or x'.

Common situations: User exports/imports a program with uppercase 'X', fills cells with '1'/'0', or a 'Select Program' preset leaves malformed values. Copy-paste from a table can introduce full-width chars or spaces.

Related errors


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