gchq/CyberChef · error · OperationError

${this.name} cannot be empty.

Error message

${this.name} cannot be empty.

What it means

Thrown by Ingredient.validate() when the resolved checkVal is empty (null, undefined, '', or a value with .length === 0) AND the ingredient disallows empty: either allowEmpty was explicitly set false in the config, or the ingredient is type option/argSelector whose permitted set does not include ''. This is recipe-argument validation, enforced before an operation runs.

Source

Thrown at src/core/Ingredient.mjs:109

        }

        // 1. check if empty
        let isEmpty = false;
        if (checkVal === null || checkVal === undefined || checkVal === "") {
            isEmpty = true;
        } else if (typeof checkVal.length === "number" && checkVal.length === 0) {
            isEmpty = true;
        }

        if (isEmpty) {
            let isAllowedOptionEmpty = false;
            if (this.type === "option" && Array.isArray(this.defaultValue)) {
                isAllowedOptionEmpty = this.defaultValue.includes("");
            } else if (this.type === "argSelector" && Array.isArray(this.defaultValue)) {
                isAllowedOptionEmpty = this.defaultValue.some(opt => opt.name === "");
            }
            if (this.allowEmpty === false || ((this.type === "option" || this.type === "argSelector") && !isAllowedOptionEmpty)) {
                throw new OperationError(`${this.name} cannot be empty.`);
            }
            return true;
        }

        // 2. maxLength check
        if (typeof this.maxLength === "number" && checkVal !== null && checkVal !== undefined) {
            if (typeof checkVal === "string" && checkVal.length > this.maxLength) {
                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);
            }
            if (Array.isArray(checkVal) && checkVal.length > this.maxLength) {
                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);
            }
            if (checkVal instanceof Uint8Array && checkVal.length > this.maxLength) {
                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);
            }
        }

        // 3. number checks

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Supply a non-empty value for the named ingredient in the recipe/args array.
  2. If empty is legitimately valid, set allowEmpty:true in the operation's ingList config for that ingredient.
  3. For option/argSelector ingredients that should permit empty, include '' (or {name:''}) in the defaultValue list.

Example fix

// before - ingredient config
{ name: 'Key', type: 'string', value: '', allowEmpty: false }

// after - either supply a value
op.ingValues = ['mysecretkey']
// or allow empty in config
{ name: 'Key', type: 'string', value: '', allowEmpty: true }
Defensive patterns

Strategy: validation

Validate before calling

function ensureNonEmpty(name, val, allowEmpty) {
  const empty = val == null || val === '' || (typeof val.length === 'number' && val.length === 0);
  if (empty && allowEmpty === false) throw new Error(`${name} must not be empty`);
}
// run before op.ingValues = [...]

Type guard

function isNonEmpty(v): v is string { return v != null && v !== '' && v.length > 0; }

Try / catch

try {
  op.ingValues = values;
} catch (e) {
  if (e instanceof OperationError && /cannot be empty/.test(e.message)) {
    // supply a value for the named ingredient
  }
}

Prevention

When it happens

Trigger: An operation ingredient declared with allowEmpty:false receives '' from a recipe; a required text field left blank in the UI; an option/argSelector ingredient whose default list omits '' and the user supplies an empty selection.

Common situations: A recipe omits or blanks a required argument (e.g. a cipher key, IV, delimiter); copying a recipe that worked for one operation into another whose arg is non-empty; UI submitting an untouched required field.

Related errors


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