{"record":{"id":"d3f61f23d6055641","repo":"different-ai/openwork","slug":"number-tostring-radix-must-be-between-2-and-36","errorCode":null,"errorMessage":"Number.toString radix must be between 2 and 36.","messagePattern":"Number\\.toString radix must be between 2 and 36\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/number.ts","lineNumber":30,"sourceCode":"    return arg\n  }\n  let result: unknown\n  switch (name) {\n    case \"toFixed\":\n      result = value.toFixed(optNum(0))\n      break\n    case \"toExponential\":\n      result = value.toExponential(optNum(0))\n      break\n    case \"toPrecision\": {\n      const digits = optNum(0)\n      result = digits === undefined ? value.toString() : value.toPrecision(digits)\n      break\n    }\n    case \"toString\": {\n      const radix = optNum(0)\n      if (radix !== undefined && (radix < 2 || radix > 36)) {\n        throw new InterpreterRuntimeError(\"Number.toString radix must be between 2 and 36.\", node)\n      }\n      result = value.toString(radix)\n      break\n    }\n    default:\n      throw new InterpreterRuntimeError(`Number method '${name}' is not available in CodeMode.`, node)\n  }\n  return boundedData(result, `Number.${name} result`)\n}\n\nexport const invokeNumberStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  const value = args[0]\n  switch (name) {\n    case \"isInteger\":\n      return Number.isInteger(value)\n    case \"isFinite\":\n      return Number.isFinite(value)\n    case \"isNaN\":","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/number.ts#L12-L48","documentation":"Number.prototype.toString(radix) only accepts an integer radix between 2 and 36 (digits 0-9 and a-z). CodeMode validates this range explicitly and throws this error for out-of-range radices (1, 0, negative, or > 36) instead of letting the engine raise a less descriptive RangeError.","triggerScenarios":"Calling value.toString(1), value.toString(0), value.toString(-2), value.toString(64) — any radix outside [2, 36] passed as the optional argument.","commonSituations":"Confusing base-64 encoding with a toString radix (toString does not do base64); computing a radix dynamically with an off-by-one (base 1 for 'unary'); porting code from bigint libs that accept radix 64.","solutions":["Use a radix in 2..36; for base-64 output use btoa or a base64 library, not toString(64).","Clamp or validate the radix before calling: if (radix < 2 || radix > 36) throw new RangeError(...).","If the radix comes from user config, sanitize it at load time to a safe default like 10."],"exampleFix":"// before\nconst encoded = value.toString(64)\n// after\nconst encoded = btoa(String(value))","handlingStrategy":"validation","validationCode":"const safeRadix = (r: number | undefined) => { if (r === undefined) return undefined; if (!Number.isInteger(r) || r < 2 || r > 36) throw new RangeError(`radix ${r} out of range 2..36`); return r }","typeGuard":"const isValidRadix = (r: unknown): r is number => typeof r === \"number\" && Number.isInteger(r) && r >= 2 && r <= 36","tryCatchPattern":"try { return value.toString(radix) } catch (e) { if (/radix must be between 2 and 36/.test(String(e))) return value.toString(10); throw e }","preventionTips":["Validate radix values at config load time (integer, 2..36)","Do not confuse base-64 encoding with toString radix — use btoa for base64","Default to radix 10 when the radix source is untrusted"],"tags":["number","codemode","range-error","argument-validation"],"backgroundTag":"invalid-function-arguments","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}