{"record":{"id":"0af45206adac0abd","repo":"different-ai/openwork","slug":"number-method-name-is-not-available-in-codemo","errorCode":null,"errorMessage":"Number method '${name}' is not available in CodeMode.","messagePattern":"Number method '(.+?)' is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/number.ts","lineNumber":36,"sourceCode":"      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)) {\n        throw new InterpreterRuntimeError(\"Number.toString radix must be between 2 and 36.\", node)\n      }\n      result = value.toString(radix)\n      break\n    }\n    default:\n      throw new InterpreterRuntimeError(`Number method '${name}' is not available in CodeMode.`, node)\n  }\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\") {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/number.ts#L18-L54","documentation":"invokeNumberMethod supports a fixed switch of Number.prototype methods (toFixed, toPrecision, toString, etc.). Any other method name hits the default branch and throws this error. The library makes unsupported method surface explicit rather than allowing a runtime 'not a function' failure deep in sandbox code.","triggerScenarios":"Calling unsupported Number.prototype methods on sandbox numbers, e.g. value.toLocaleString(\"de-DE\"), value.toExponential(2), or typos like value.toFixd(2).","commonSituations":"Locale-aware formatting in generated code (toLocaleString) — CodeMode does not support it; porting numeric formatting code that used toExponential; simple typos in method names.","solutions":["Use supported methods only: toFixed, toPrecision, toString (see the switch in packages/codemode/src/stdlib/number.ts).","For locale formatting, pre-format the string outside CodeMode or format manually with toFixed.","For toExponential, approximate via toPrecision or implement conversion in sandbox JS."],"exampleFix":"// before\nconst s = value.toLocaleString(\"de-DE\")\n// after\nconst s = value.toFixed(2).replace(\".\", \",\")","handlingStrategy":"validation","validationCode":"const allowedNumberMethods = new Set([\"toFixed\", \"toPrecision\", \"toString\"])\nif (!allowedNumberMethods.has(methodName)) throw new Error(`Number.${methodName} is not whitelisted in CodeMode`)","typeGuard":"const isNumberMethod = (n: string): n is \"toFixed\" | \"toPrecision\" | \"toString\" => allowedNumberMethods.has(n)","tryCatchPattern":"try { return value[methodName](...args) } catch (e) { if (/is not available in CodeMode/.test(String(e))) return numberFallback(value, methodName, args); throw e }","preventionTips":["Restrict sandbox code to toFixed, toPrecision, and toString","Replace toLocaleString with manual formatting (toFixed + string ops)","Replace toExponential with toPrecision or a hand-rolled formatter","Watch for typos in method names — the whitelist rejects unknown names explicitly"],"tags":["number","codemode","unsupported-api","whitelist"],"backgroundTag":"method-not-supported","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}