{"record":{"id":"0a2bfa9065d466cd","repo":"different-ai/openwork","slug":"array-from-does-not-support-a-map-function-in","errorCode":null,"errorMessage":"Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.","messagePattern":"Array\\.from\\(\\.\\.\\.\\) does not support a map function in CodeMode; call \\.map\\(\\) on the result instead\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":520,"sourceCode":"    case \"concat\": {\n      result = value.concat(...args.map((_, index) => str(index)))\n      break\n    }\n    default:\n      throw new InterpreterRuntimeError(`String method '${name}' is not available in CodeMode.`, node)\n  }\n  return boundedData(result, `String.${name} result`)\n}\n\nconst invokeArrayStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  switch (name) {\n    case \"isArray\":\n      return Array.isArray(args[0])\n    case \"of\":\n      return [...args]\n    case \"from\": {\n      if (args.length > 1) {\n        throw new InterpreterRuntimeError(\n          \"Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.\",\n          node,\n          \"UnsupportedSyntax\",\n          [supportedSyntaxMessage],\n        )\n      }\n      // Map/Set materialize directly (the data checkpoint would serialize them to {}).\n      if (args[0] instanceof SandboxMap)\n        return Array.from((args[0] as SandboxMap).map.entries(), ([key, item]) => [key, item])\n      if (args[0] instanceof SandboxSet) return Array.from((args[0] as SandboxSet).set.values())\n      if (args[0] instanceof SandboxURLSearchParams) {\n        return Array.from(args[0].params.entries(), ([key, value]) => [key, value])\n      }\n      const source = boundedData(args[0], \"Array.from input\")\n      if (typeof source === \"string\") return Array.from(source)\n      if (Array.isArray(source)) return [...source]\n      if (\n        source !== null &&","sourceCodeStart":502,"sourceCodeEnd":538,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L502-L538","documentation":"CodeMode supports Array.from only for converting an array-like/iterable into an array. The two-argument form where the second parameter is a mapping function is deliberately rejected with an UnsupportedSyntax error, directing developers to chain .map() separately. This keeps the interpreter's implementation surface small and error hints actionable.","triggerScenarios":"Calling Array.from(iterable, mapFn) with more than one argument inside CodeMode, e.g. Array.from({length: 5}, (_, i) => i * 2) or Array.from(str, ch => ch.toUpperCase()).","commonSituations":"Idiomatic JS one-liners ported into CodeMode; LLM-generated code that uses the mapFn overload; refactoring existing scripts into sandboxed code without adapting Array.from usage.","solutions":["Call Array.from with a single argument, then chain .map() on the result","Build the values with a supported loop or Array constructor pattern","If mapping a range, use a supported helper or a for loop pushing into an array"],"exampleFix":"// before\nconst squares = Array.from({length: 5}, (_, i) => i * i);\n// after\nconst squares = Array.from({length: 5}).map((_, i) => i * i);","handlingStrategy":"validation","validationCode":"// Reject two-argument Array.from before running CodeMode\nif (/Array\\.from\\s*\\([^)]*,/.test(code)) {\n  throw new Error('CodeMode code uses Array.from with a map function; use .map() instead');\n}","typeGuard":"function isSingleArgArrayFrom(call) { return call.arguments.length === 1; }","tryCatchPattern":null,"preventionTips":["Always call Array.from with exactly one argument in sandbox code","Chain .map() after Array.from for transformations","Add a pre-execution lint rule for the Array.from(x, fn) pattern"],"tags":["codemode","sandbox","array-from","unsupported-syntax"],"backgroundTag":"unsupported-api-in-sandbox","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}