{"record":{"id":"086cad94463daaa7","repo":"gchq/CyberChef","slug":"error-input-must-be-a-number","errorCode":null,"errorMessage":"Error: Input must be a number","messagePattern":"Error: Input must be a number","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ToBase.mjs","lineNumber":46,"sourceCode":"            {\n                \"name\": \"Radix\",\n                \"type\": \"number\",\n                \"value\": 36,\n                \"min\": 2,\n                \"max\": 36,\n                \"integer\": true,\n            }\n        ];\n    }\n\n    /**\n     * @param {BigNumber} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        if (!input) {\n            throw new OperationError(\"Error: Input must be a number\");\n        }\n        const radix = args[0];\n        return input.toString(radix);\n    }\n\n}\n\nexport default ToBase;\n","sourceCodeStart":28,"sourceCodeEnd":55,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ToBase.mjs#L28-L55","documentation":"To Base rejects input that is falsy (`!input`). Because the operation expects a BigNumber and renders it in a target radix, a missing/null/undefined input (no valid number produced upstream) cannot be converted. Note the truthiness check means a numeric 0 represented as a primitive 0 would also be rejected, though normal BigNumber objects are truthy.","triggerScenarios":"Chaining To Base after an operation that yields null/undefined/empty instead of a BigNumber, or passing an input that the BigNumber layer could not materialise.","commonSituations":"A preceding conversion producing no number; a recipe where the input field is empty; a parsing step that silently returns null.","solutions":["Ensure the previous operation outputs a valid decimal number / BigNumber.","Provide a concrete numeric input such as 255.","If you genuinely need to convert 0, pass it as an explicit BigNumber object so it is truthy."],"exampleFix":"// before: input = null            -> !input true -> throws\n// after:  input = 255              -> converts to base 36 as '73'","handlingStrategy":"type-guard","validationCode":"if (input === null || input === undefined || (typeof input === \"number\" && !Number.isFinite(input))) {\n  throw new Error(\"To Base requires a numeric input\");\n}","typeGuard":"const hasNumericInput = v => v !== null && v !== undefined && !(typeof v === \"number\" && Number.isNaN(v));","tryCatchPattern":"try { toBase(input, radix); }\ncatch (e) { if (/Input must be a number/.test(e.message)) { input = new BigNumber(0); } else throw e; }","preventionTips":["Guarantee the upstream operation yields a BigNumber.","Avoid relying on falsy checks for numeric 0 — pass explicit BigNumber objects.","Default empty inputs to a concrete number before conversion."],"tags":["number","base","validation","truthiness"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}