gchq/CyberChef · error · OperationError

Failed to set value of ingredient '${this._ingList[i].name}'

Error message

Failed to set value of ingredient '${this._ingList[i].name}': ${err}

What it means

Thrown by the Operation.ingValues setter (line 249) wrapping any exception raised while assigning this._ingList[i].value = val. The inner assignment triggers Ingredient.prepare(), so the most common inner cause is error 13 ('Invalid ingredient value. Not a number'). It also fires as a TypeError wrapped here when the ingValues array is longer than _ingList (this._ingList[i] is undefined).

Source

Thrown at src/core/Operation.mjs:249

     *
     * @param {Ingredient} ingredient
     */
    addIngredient(ingredient) {
        this._ingList.push(ingredient);
    }


    /**
     * Set the Ingredient values for this Operation.
     *
     * @param {Object[]} ingValues
     */
    set ingValues(ingValues) {
        ingValues.forEach((val, i) => {
            try {
                this._ingList[i].value = val;
            } catch (err) {
                throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);
            }
        });
    }


    /**
     * Get the Ingredient values for this Operation.
     *
     * @returns {Object[]}
     */
    get ingValues() {
        return this._ingList.map(ing => ing.value);
    }


    /**
     * Set whether this Operation has a breakpoint.
     *

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Read the inner ${err}: 'Not a number' points to error 13 (fix the offending arg); 'Cannot set property value of undefined' means your ingValues array is longer than the operation's ingredient list.
  2. Match the length and types of ingValues to the operation's declared ingList.
  3. Construct the operation and inspect op.ingList length before assigning ingValues.

Example fix

// before - op has 2 ingredients but 3 values supplied
op.ingValues = ['a', 'b', 'c'];

// after
op.ingValues = ['a', 'b'];

// before - number ingredient given non-numeric text
op.ingValues = ['xyz'];
// after
op.ingValues = ['16'];
Defensive patterns

Strategy: validation

Validate before calling

function safeIngValues(op, values) {
  if (values.length > op.ingList.length) {
    throw new Error(`got ${values.length} args, op has ${op.ingList.length}`);
  }
  op.ingValues = values;
}

Type guard

function ingValuesMatch(op, values): values is unknown[] { return Array.isArray(values) && values.length <= op.ingList.length; }

Try / catch

try { op.ingValues = values; } catch (e) {
  if (e instanceof OperationError && /Failed to set value of ingredient/.test(e.message)) {
    // inspect inner cause: count mismatch or prepare error (error 13)
  }
}

Prevention

When it happens

Trigger: op.ingValues = ['abc'] where ingredient 0 is type number (prepare throws, wrapped); op.ingValues has more entries than the operation declares (undefined.value throws TypeError, wrapped); a byteArray ingredient given malformed hex that fromHex chokes on.

Common situations: Hydrating an operation from a recipe config whose args are malformed or mismatched in count; a recipe built for an older version of the operation with a different arg list; programmatic construction passing a wrong-typed arg.

Related errors


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