{"record":{"id":"86d1d98f20afe9b0","repo":"different-ai/openwork","slug":"number-name-expects-a-number-argument","errorCode":null,"errorMessage":"Number.${name} expects a number argument.","messagePattern":"Number\\.(.+?) expects a number argument\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/number.ts","lineNumber":11,"sourceCode":"export const numberMethods = new Set([\"toFixed\", \"toPrecision\", \"toExponential\", \"toString\"])\n\nexport const numberConstants = new Set([\"MAX_SAFE_INTEGER\", \"MIN_SAFE_INTEGER\", \"MAX_VALUE\", \"MIN_VALUE\", \"EPSILON\"])\n\nexport const numberStatics = new Set([\"isInteger\", \"isFinite\", \"isNaN\", \"isSafeInteger\", \"parseInt\", \"parseFloat\"])\n\nexport const invokeNumberMethod = (value: number, name: string, args: Array<unknown>, node: AstNode): unknown => {\n  const optNum = (index: number): number | undefined => {\n    const arg = args[index]\n    if (arg === undefined) return undefined\n    if (typeof arg !== \"number\") throw new InterpreterRuntimeError(`Number.${name} expects a number argument.`, node)\n    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)) {","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/number.ts#L1-L29","documentation":"optNum validates optional numeric parameters (digits for toFixed/toPrecision, radix for toString) inside invokeNumberMethod. If the slot is provided but is not a number, the library throws this error rather than coercing, since silent coercion of e.g. digits=\"2\" would hide bugs.","triggerScenarios":"Calling value.toFixed(\"2\"), value.toPrecision(undefined-as-string), value.toString(\"16\") — any call where the optional parameter is present with typeof !== \"number\". optNum is shared by digits and radix slots, so it fires for all of them.","commonSituations":"Receiving numeric parameters as strings from JSON config or query params; passing user input directly as precision; accidentally passing a string template value where a number was intended.","solutions":["Convert the argument with Number(x) or parseInt/parseFloat before the call.","If the value may be absent, pass undefined explicitly instead of a string placeholder.","Validate user-supplied formatting parameters at the boundary before invoking the method."],"exampleFix":"// before\nconst s = price.toFixed(input.digits)\n// after\nconst s = price.toFixed(Number(input.digits ?? 2))","handlingStrategy":"type-guard","validationCode":"const digits = typeof d === \"number\" ? d : Number(d)\nif (d !== undefined && Number.isNaN(digits)) throw new TypeError(\"formatting digits must be numeric\")","typeGuard":"const isNumArg = (v: unknown): v is number => typeof v === \"number\"","tryCatchPattern":"try { return value.toFixed(d) } catch (e) { if (/expects a number argument/.test(String(e))) return value.toFixed(Number(d)); throw e }","preventionTips":["Always Number()-convert formatting parameters that come from JSON, env, or user input","Pass undefined (not a string placeholder) when omitting optional numeric parameters","Validate numeric options at the config boundary"],"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"}