{"record":{"id":"d180b2c480d79ac2","repo":"gchq/CyberChef","slug":"invalid-alphabet-size-required-to-be-integer","errorCode":null,"errorMessage":"Invalid alphabet size, required to be integer.","messagePattern":"Invalid alphabet size, required to be integer\\.","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"warning","filePath":"src/core/operations/GenerateDeBruijnSequence.mjs","lineNumber":54,"sourceCode":"                value: 3\n            }\n        ];\n    }\n\n    /**\n     * @param {string} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const [k, n] = args;\n\n        if (k < 2 || k > 9) {\n            throw new OperationError(\"Invalid alphabet size, required to be between 2 and 9 (inclusive).\");\n        }\n\n        if (!Number.isInteger(k)) {\n            throw new OperationError(\"Invalid alphabet size, required to be integer.\");\n        }\n\n        if (!Number.isInteger(n)) {\n            throw new OperationError(\"Invalid key length, required to be integer.\");\n        }\n\n        if (n < 2) {\n            throw new OperationError(\"Invalid key length, required to be at least 2.\");\n        }\n\n        if (Math.pow(k, n) > 50000) {\n            throw new OperationError(\"Too many permutations, please reduce k^n to under 50,000.\");\n        }\n\n        const a = new Array(k * n).fill(0);\n        const sequence = [];\n\n        (function db(t = 1, p = 1) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateDeBruijnSequence.mjs#L36-L72","documentation":"Second validation in Generate De Bruijn Sequence: requires `k` to be an integer. It runs only after the 2..9 range check passes, so it catches fractional values that nonetheless fell inside the range (e.g. k=2.5, k=8.1). Number.isInteger rejects NaN, Infinity, and any non-whole float.","triggerScenarios":"Entering a decimal alphabet size like 2.5 or 7.3; the value slipping in as a float via a programmatic recipe even though the field is numeric.","commonSituations":"Number field allowing decimals; scripting the op with a computed float that wasn't rounded.","solutions":["Round k to a whole number before running.","Enter only integers in the Alphabet size field.","If computing k, wrap with Math.round or Math.floor."],"exampleFix":"// before\nargs = [2.5, 4];\n// after\nargs = [2, 4]; // or Math.round(2.5) === 3","handlingStrategy":"validation","validationCode":"if (!Number.isInteger(k)) throw new Error(\"Alphabet size k must be an integer\");","typeGuard":"function isInt(k){return Number.isInteger(k);}","tryCatchPattern":null,"preventionTips":["Round k before passing.","Enter whole numbers only in the alphabet size field."],"tags":["combinatorics","de-bruijn","argument-validation","type"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}