{"record":{"id":"16e53c91c62c3f5b","repo":"gchq/CyberChef","slug":"this-name-must-be-an-integer","errorCode":null,"errorMessage":"${this.name} must be an integer.","messagePattern":"(.+?) must be an integer\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/Ingredient.mjs","lineNumber":133,"sourceCode":"        if (typeof this.maxLength === \"number\" && checkVal !== null && checkVal !== undefined) {\n            if (typeof checkVal === \"string\" && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (Array.isArray(checkVal) && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (checkVal instanceof Uint8Array && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n        }\n\n        // 3. number checks\n        if (this.type === \"number\") {\n            if (checkVal === null || checkVal === undefined || isNaN(checkVal)) {\n                throw new OperationError(`${this.name} must be a number.`);\n            }\n            if (this.integer && !Number.isInteger(checkVal)) {\n                throw new OperationError(`${this.name} must be an integer.`);\n            }\n            if (typeof this.min === \"number\" && checkVal < this.min) {\n                throw new OperationError(`${this.name} must be greater than or equal to ${this.min}.`);\n            }\n            if (typeof this.max === \"number\" && checkVal > this.max) {\n                throw new OperationError(`${this.name} must be less than or equal to ${this.max}.`);\n            }\n        }\n\n        // 4. option checks\n        if (this.type === \"option\") {\n            if (Array.isArray(this.defaultValue)) {\n                const permittedOptions = this.defaultValue.filter(opt => {\n                    if (typeof opt !== \"string\") return false;\n                    return !opt.match(/^\\[\\/?[a-z0-9 -()^]+\\]$/i);\n                });\n                const valStr = (checkVal !== null && checkVal !== undefined) ? String(checkVal).toLowerCase() : \"\";\n                const matchedOption = permittedOptions.find(opt => opt.toLowerCase() === valStr);","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Ingredient.mjs#L115-L151","documentation":"Thrown by Ingredient.validate() when type is 'number', the value is a valid number, but the ingredient has integer:true set and Number.isInteger(checkVal) is false (line 133). The number is finite but fractional.","triggerScenarios":"An integer-only ingredient (block size, bit length, iteration count, radix) receives a decimal value such as 3.5 from the recipe.","commonSituations":"User types a decimal into an integer field; a computed arg (division, log) yields a fractional result fed back as an ingredient; recipe imported from a tool that emits floats.","solutions":["Pass an integer value (Math.round / Math.floor the computed value before assigning).","If fractional values are acceptable, set integer:false in the ingredient config.","Validate Number.isInteger(value) before assigning ingValues."],"exampleFix":"// before\nop.ingValues = [3.5]; // integer:true ingredient\n\n// after\nop.ingValues = [Math.round(3.5)]; // 4","handlingStrategy":"validation","validationCode":"if (ingredient.integer && typeof val === 'number' && !Number.isInteger(val)) {\n  throw new Error(`${name} must be an integer`);\n}","typeGuard":"function isInteger(v): v is number { return typeof v === 'number' && Number.isInteger(v); }","tryCatchPattern":"try { op.ingValues = [val]; } catch (e) { if (/must be an integer/.test(e.message)) { val = Math.round(val); } }","preventionTips":["Round/floor computed values before assigning to integer ingredients.","Set integer:false in config if fractional values are valid.","Validate Number.isInteger on the client side."],"tags":["ingredient","validation","integer","number","operationerror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}