{"record":{"id":"22e1ce1f01239647","repo":"different-ai/openwork","slug":"number-name-is-not-available-in-codemode","errorCode":null,"errorMessage":"Number.${name} is not available in CodeMode.","messagePattern":"Number\\.(.+?) is not available in CodeMode\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/number.ts","lineNumber":62,"sourceCode":"    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\") {\n        throw new InterpreterRuntimeError(\"Number.parseInt expects a numeric radix.\", node)\n      }\n      return parseInt(coerceToString(value), radix)\n    }\n    case \"parseFloat\":\n      return parseFloat(coerceToString(value))\n    default:\n      throw new InterpreterRuntimeError(`Number.${name} is not available in CodeMode.`, node)\n  }\n}\nimport { type AstNode, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { boundedData, coerceToString } from \"./value.js\"\n","sourceCodeStart":44,"sourceCodeEnd":67,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/number.ts#L44-L67","documentation":"CodeMode sandboxes the JS interpreter and only exposes a whitelisted subset of Number statics (parseInt, parseFloat, etc.). invokeNumberStatic throws this when a script calls a Number static method that is not in the allowed switch, so authors know the capability is intentionally unavailable rather than a bug.","triggerScenarios":"Calling any Number static not handled by invokeNumberStatic, e.g. Number.isNaN(x), Number.isFinite(x), Number.isInteger(x), Number.isSafeInteger(x), Number.EPSILON access, Number.parseFloat vs Number.parseFloat alias, Number.MAX_SAFE_INTEGER, or Number.fromString-style calls inside CodeMode scripts.","commonSituations":"Porting regular JS utilities into CodeMode scripts where Number.isInteger/isNaN were used for validation; polyfill-style code that assumes full ECMAScript statics; LLM-generated scripts using Number.isNaN because CodeMode disallows global isNaN.","solutions":["Replace Number.isNaN(x) with x !== x or a typeof/JSON-based check allowed by the sandbox","Replace Number.isFinite/Number.isInteger with typeof x === 'number' && Number.isFinite alternatives implemented via arithmetic, or guard with typeof checks","Check the CodeMode stdlib docs for the supported Number statics list and rewrite the script accordingly","If the static is broadly needed, add a case to invokeNumberStatic in packages/codemode/src/stdlib/number.ts and a test"],"exampleFix":"// before\nif (Number.isNaN(value)) return 0\n// after\nif (typeof value !== 'number' || value !== value) return 0","handlingStrategy":"type-guard","validationCode":"const allowedNumberStatics = new Set(['parseInt','parseFloat'])\nif (!allowedNumberStatics.has(fnName)) throw new Error(`Number.${fnName} unsupported in CodeMode`)\nif (typeof value !== 'number') throw new Error('expected number')","typeGuard":"const isCodeModeNumberStatic = (name: string): name is 'parseInt' | 'parseFloat' => ['parseInt','parseFloat'].includes(name)","tryCatchPattern":"try {\n  Number[fnName](arg)\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && e.message.includes('Number.')) {\n    // fall back to sandbox-safe arithmetic checks\n  }\n  throw e\n}","preventionTips":["Consult the CodeMode Number stdlist before porting vanilla JS","Replace Number.isNaN/isFinite with typeof and self-comparison checks","Avoid Number constants (EPSILON, MAX_SAFE_INTEGER) in sandbox scripts","Add a CI check that scripts only use whitelisted statics"],"tags":["codemode","sandbox","javascript","stdlib"],"backgroundTag":"sandboxed-api-not-available","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}