different-ai/openwork · error · InterpreterRuntimeError

parseInt expects a numeric radix.

Error message

parseInt expects a numeric radix.

What it means

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.

Source

Thrown at packages/codemode/src/stdlib/value.ts:69

  return value !== null && typeof value === "object" && !Array.isArray(value) ? Number.NaN : Number(value)
}

export const invokeCoercion = (ref: CoercionFunction, args: Array<unknown>, node: AstNode): unknown => {
  const raw = args[0]
  if (isSandboxValue(raw)) {
    if (ref.name === "Boolean") return true
    if (ref.name === "Number") return coerceToNumber(raw)
    if (ref.name === "String") return coerceToString(raw)
    if (ref.name === "parseInt") return parseInt(coerceToString(raw))
    return parseFloat(coerceToString(raw))
  }
  const value = boundedData(args[0], `${ref.name} input`)
  if (ref.name === "Number") return coerceToNumber(value)
  if (ref.name === "Boolean") return Boolean(value)
  if (ref.name === "parseInt") {
    const radix = args[1]
    if (radix !== undefined && typeof radix !== "number") {
      throw new InterpreterRuntimeError("parseInt expects a numeric radix.", node)
    }
    return parseInt(coerceToString(value), radix)
  }
  if (ref.name === "parseFloat") return parseFloat(coerceToString(value))
  return coerceToString(value)
}
import { type AstNode, CoercionFunction, InterpreterRuntimeError } from "../interpreter/model.js"
import { copyIn, type SafeObject } from "../tool-runtime.js"
import {
  isSandboxValue,
  SandboxDate,
  SandboxMap,
  SandboxRegExp,
  SandboxSet,
  SandboxURL,
  SandboxURLSearchParams,
} from "../values.js"

View on GitHub (pinned to 2b7df46e8a)

Solutions

  1. Convert the radix: `parseInt(value, Number(radix))`.
  2. Omit the radix entirely when it is null/undefined: `parseInt(value, radix ?? undefined)` won't help for null — pass `radix === null ? undefined : radix`.
  3. Fix the source so the radix is stored as a number.
  4. Always pass an explicit numeric radix (e.g. 10 or 16) to avoid ambiguity.

Example fix

// before
parseInt(text, radix) // radix is "16"
// after
parseInt(text, Number(radix))
Defensive patterns

Strategy: type-guard

Validate before calling

if (radix !== undefined && typeof radix !== "number") throw new TypeError("radix must be a number")

Type guard

const isValidRadix = (r) => r === undefined || (typeof r === "number" && Number.isInteger(r))

Try / catch

try { n = parseInt(text, radix) } catch (e) { n = NaN }

Prevention

When it happens

Trigger: `parseInt("ff", "16")` or `parseInt("10", null)` inside CodeMode.

Common situations: Radix read from config/JSON as a string ("16"); passing null intending 'default radix' instead of omitting the argument.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/cfdf8ab415a30d5e. Report an issue: GitHub.