different-ai/openwork · error · InterpreterRuntimeError

Number.parseInt expects a numeric radix.

Error message

Number.parseInt expects a numeric radix.

What it means

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.

Solutions

  1. Convert the radix with Number() or parseInt before passing it: parseInt(value, Number(radix)).
  2. Omit the radix entirely if you want the default (though best practice is to always pass a numeric radix).
  3. Validate config-sourced radix values at startup: typeof r === "number" && r >= 2 && r <= 36.

Example fix

// before
const n = Number.parseInt(input, config.radix)
// after
const n = Number.parseInt(input, Number(config.radix) || 10)
Defensive patterns

Strategy: type-guard

Validate before calling

const radixNum = radix === undefined ? undefined : Number(radix)
if (radixNum !== undefined && !Number.isInteger(radixNum)) throw new TypeError("parseInt radix must be an integer number")

Type guard

const isRadix = (v: unknown): v is number => typeof v === "number" && Number.isInteger(v)

Try / catch

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 }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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

Appendix: source

Thrown at packages/codemode/src/stdlib/number.ts:55

  }
  return boundedData(result, `Number.${name} result`)
}

export const invokeNumberStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {
  const value = args[0]
  switch (name) {
    case "isInteger":
      return Number.isInteger(value)
    case "isFinite":
      return Number.isFinite(value)
    case "isNaN":
      return Number.isNaN(value)
    case "isSafeInteger":
      return Number.isSafeInteger(value)
    case "parseInt": {
      const radix = args[1]
      if (radix !== undefined && typeof radix !== "number") {
        throw new InterpreterRuntimeError("Number.parseInt expects a numeric radix.", node)
      }
      return parseInt(coerceToString(value), radix)
    }
    case "parseFloat":
      return parseFloat(coerceToString(value))
    default:
      throw new InterpreterRuntimeError(`Number.${name} is not available in CodeMode.`, node)
  }
}
import { type AstNode, InterpreterRuntimeError } from "../interpreter/model.js"
import { boundedData, coerceToString } from "./value.js"

View on GitHub (pinned to 2b7df46e8a)