{"record":{"id":"2a58914b5a585257","repo":"gchq/CyberChef","slug":"failed-to-set-value-of-ingredient-this-inglist","errorCode":null,"errorMessage":"Failed to set value of ingredient '${this._ingList[i].name}': ${err}","messagePattern":"Failed to set value of ingredient '(.+?)': (.+?)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/Operation.mjs","lineNumber":249,"sourceCode":"     *\n     * @param {Ingredient} ingredient\n     */\n    addIngredient(ingredient) {\n        this._ingList.push(ingredient);\n    }\n\n\n    /**\n     * Set the Ingredient values for this Operation.\n     *\n     * @param {Object[]} ingValues\n     */\n    set ingValues(ingValues) {\n        ingValues.forEach((val, i) => {\n            try {\n                this._ingList[i].value = val;\n            } catch (err) {\n                throw new OperationError(`Failed to set value of ingredient '${this._ingList[i].name}': ${err}`);\n            }\n        });\n    }\n\n\n    /**\n     * Get the Ingredient values for this Operation.\n     *\n     * @returns {Object[]}\n     */\n    get ingValues() {\n        return this._ingList.map(ing => ing.value);\n    }\n\n\n    /**\n     * Set whether this Operation has a breakpoint.\n     *","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Operation.mjs#L231-L267","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Match the length and types of ingValues to the operation's declared ingList.","Construct the operation and inspect op.ingList length before assigning ingValues."],"exampleFix":"// before - op has 2 ingredients but 3 values supplied\nop.ingValues = ['a', 'b', 'c'];\n\n// after\nop.ingValues = ['a', 'b'];\n\n// before - number ingredient given non-numeric text\nop.ingValues = ['xyz'];\n// after\nop.ingValues = ['16'];","handlingStrategy":"validation","validationCode":"function safeIngValues(op, values) {\n  if (values.length > op.ingList.length) {\n    throw new Error(`got ${values.length} args, op has ${op.ingList.length}`);\n  }\n  op.ingValues = values;\n}","typeGuard":"function ingValuesMatch(op, values): values is unknown[] { return Array.isArray(values) && values.length <= op.ingList.length; }","tryCatchPattern":"try { op.ingValues = values; } catch (e) {\n  if (e instanceof OperationError && /Failed to set value of ingredient/.test(e.message)) {\n    // inspect inner cause: count mismatch or prepare error (error 13)\n  }\n}","preventionTips":["Compare values.length against op.ingList.length before assigning.","Match each arg's type to its ingredient declaration.","Build ingValues from the operation's own config, not hand-typed arrays."],"tags":["operation","ingredient","hydration","operationerror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}