gchq/CyberChef · error · OperationError

Invalid ingredient value. Not a number: ${sample}

Error message

Invalid ingredient value. Not a number: ${sample}

What it means

Thrown by Ingredient.prepare() (line 237) when the ingredient type is 'number', data is not null, and parseFloat(data) returns NaN. prepare() runs inside the Ingredient value setter, so this fires DURING assignment of ingValues - earlier than the validate() number check (error 7). The sample is the truncated raw input.

Source

Thrown at src/core/Ingredient.mjs:237

        switch (type) {
            case "binaryString":
            case "binaryShortString":
            case "editableOption":
            case "editableOptionShort":
                return Utils.parseEscapedChars(data);
            case "byteArray":
                if (typeof data == "string") {
                    data = data.replace(/\s+/g, "");
                    return fromHex(data);
                } else {
                    return data;
                }
            case "number":
                if (data === null) return data;
                number = parseFloat(data);
                if (isNaN(number)) {
                    const sample = Utils.truncate(data.toString(), 10);
                    throw new OperationError(
                        "Invalid ingredient value. Not a number: " + sample,
                    );
                }
                return number;
            default:
                return data;
        }
    }

}

export default Ingredient;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Pass a value parseFloat can handle (a numeric string like '16' or a number).
  2. Parse and validate the source text yourself before assigning to ingValues.
  3. Provide a numeric defaultValue so empty input falls back gracefully.

Example fix

// before
op.ingValues = ['abc']; // number ingredient

// after
op.ingValues = ['16']; // or the number 16
Defensive patterns

Strategy: validation

Validate before calling

function prepareNumberArg(data) {
  if (data == null) return data;
  const n = parseFloat(data);
  if (isNaN(n)) throw new Error(`Not a number: ${String(data).slice(0, 10)}`);
  return n;
}
// call before op.ingValues = [rawText]

Type guard

function isParsableNumber(v): v is string { return v != null && !isNaN(parseFloat(v)); }

Try / catch

try { op.ingValues = [rawText]; } catch (e) {
  if (e instanceof OperationError && /Not a number/.test(e.message)) { /* rawText unparseable */ }
}

Prevention

When it happens

Trigger: Setting ingredient.value = 'abc' on a number ingredient (parseFloat('abc') is NaN); passing a non-numeric string where a number is expected via op.ingValues; an object/symbol coerced to a non-numeric string.

Common situations: Recipe supplies a text value for a numeric arg; UI sends a raw textfield string into a number ingredient without client-side parsing; programmatic recipe build using an untrimmed/non-numeric string.

Related errors


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