{"record":{"id":"cfdf8ab415a30d5e","repo":"different-ai/openwork","slug":"parseint-expects-a-numeric-radix","errorCode":null,"errorMessage":"parseInt expects a numeric radix.","messagePattern":"parseInt expects a numeric radix\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/value.ts","lineNumber":69,"sourceCode":"  return value !== null && typeof value === \"object\" && !Array.isArray(value) ? Number.NaN : Number(value)\n}\n\nexport const invokeCoercion = (ref: CoercionFunction, args: Array<unknown>, node: AstNode): unknown => {\n  const raw = args[0]\n  if (isSandboxValue(raw)) {\n    if (ref.name === \"Boolean\") return true\n    if (ref.name === \"Number\") return coerceToNumber(raw)\n    if (ref.name === \"String\") return coerceToString(raw)\n    if (ref.name === \"parseInt\") return parseInt(coerceToString(raw))\n    return parseFloat(coerceToString(raw))\n  }\n  const value = boundedData(args[0], `${ref.name} input`)\n  if (ref.name === \"Number\") return coerceToNumber(value)\n  if (ref.name === \"Boolean\") return Boolean(value)\n  if (ref.name === \"parseInt\") {\n    const radix = args[1]\n    if (radix !== undefined && typeof radix !== \"number\") {\n      throw new InterpreterRuntimeError(\"parseInt expects a numeric radix.\", node)\n    }\n    return parseInt(coerceToString(value), radix)\n  }\n  if (ref.name === \"parseFloat\") return parseFloat(coerceToString(value))\n  return coerceToString(value)\n}\nimport { type AstNode, CoercionFunction, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { copyIn, type SafeObject } from \"../tool-runtime.js\"\nimport {\n  isSandboxValue,\n  SandboxDate,\n  SandboxMap,\n  SandboxRegExp,\n  SandboxSet,\n  SandboxURL,\n  SandboxURLSearchParams,\n} from \"../values.js\"\n","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/value.ts#L51-L87","documentation":"The sandboxed parseInt requires the optional second argument (radix) to be a number when provided. Any other type — string, null, boolean — is rejected with this error instead of being silently coerced, matching the sandbox's strict-argument philosophy.","triggerScenarios":"`parseInt(\"ff\", \"16\")` or `parseInt(\"10\", null)` inside CodeMode.","commonSituations":"Radix read from config/JSON as a string (\"16\"); passing null intending 'default radix' instead of omitting the argument.","solutions":["Convert the radix: `parseInt(value, Number(radix))`.","Omit the radix entirely when it is null/undefined: `parseInt(value, radix ?? undefined)` won't help for null — pass `radix === null ? undefined : radix`.","Fix the source so the radix is stored as a number.","Always pass an explicit numeric radix (e.g. 10 or 16) to avoid ambiguity."],"exampleFix":"// before\nparseInt(text, radix) // radix is \"16\"\n// after\nparseInt(text, Number(radix))","handlingStrategy":"type-guard","validationCode":"if (radix !== undefined && typeof radix !== \"number\") throw new TypeError(\"radix must be a number\")","typeGuard":"const isValidRadix = (r) => r === undefined || (typeof r === \"number\" && Number.isInteger(r))","tryCatchPattern":"try { n = parseInt(text, radix) } catch (e) { n = NaN }","preventionTips":["Always pass an explicit integer radix","Coerce config values with Number() before use","Use undefined (not null) to omit optional args"],"tags":["codemode","parsing","type-error","sandbox"],"backgroundTag":"argument-type-mismatch","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}