{"record":{"id":"351ec228e183bdcd","repo":"different-ai/openwork","slug":"number-parseint-expects-a-numeric-radix","errorCode":null,"errorMessage":"Number.parseInt expects a numeric radix.","messagePattern":"Number\\.parseInt expects a numeric radix\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/number.ts","lineNumber":55,"sourceCode":"  }\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\":\n      return Number.isNaN(value)\n    case \"isSafeInteger\":\n      return Number.isSafeInteger(value)\n    case \"parseInt\": {\n      const radix = args[1]\n      if (radix !== undefined && typeof radix !== \"number\") {\n        throw new InterpreterRuntimeError(\"Number.parseInt expects a numeric radix.\", node)\n      }\n      return parseInt(coerceToString(value), radix)\n    }\n    case \"parseFloat\":\n      return parseFloat(coerceToString(value))\n    default:\n      throw new InterpreterRuntimeError(`Number.${name} is not available in CodeMode.`, node)\n  }\n}\nimport { type AstNode, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { boundedData, coerceToString } from \"./value.js\"\n","sourceCodeStart":37,"sourceCodeEnd":67,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/number.ts#L37-L67","documentation":"When invoking the static Number.parseInt, CodeMode validates the optional radix argument: if provided, it must be a number. Passing a string or other type throws this error, because parseInt's radix must be numeric and silent coercion could produce surprising parse bases.","triggerScenarios":"Calling Number.parseInt(str, \"16\"), Number.parseInt(value, radixVar) where radixVar is undefined-as-string or came from config as a string, or passing null as the radix.","commonSituations":"Radix read from JSON/env config where everything is a string ('16'); passing the output of a prompt or CLI arg directly as radix; confusing parseInt with parseFloat calls where the second arg doesn't exist.","solutions":["Convert the radix with Number() or parseInt before passing it: parseInt(value, Number(radix)).","Omit the radix entirely if you want the default (though best practice is to always pass a numeric radix).","Validate config-sourced radix values at startup: typeof r === \"number\" && r >= 2 && r <= 36."],"exampleFix":"// before\nconst n = Number.parseInt(input, config.radix)\n// after\nconst n = Number.parseInt(input, Number(config.radix) || 10)","handlingStrategy":"type-guard","validationCode":"const radixNum = radix === undefined ? undefined : Number(radix)\nif (radixNum !== undefined && !Number.isInteger(radixNum)) throw new TypeError(\"parseInt radix must be an integer number\")","typeGuard":"const isRadix = (v: unknown): v is number => typeof v === \"number\" && Number.isInteger(v)","tryCatchPattern":"try { return Number.parseInt(str, radix) } catch (e) { if (/expects a numeric radix/.test(String(e))) return Number.parseInt(str, Number(radix) || 10); throw e }","preventionTips":["Convert config/env-sourced radix strings with Number() before passing them","Always pass an explicit numeric radix to parseInt (default pitfall: strings like '08')","Type the radix parameter as number | undefined in wrappers around parseInt"],"tags":["number","codemode","type-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"}