{"record":{"id":"83be134046eb006e","repo":"different-ai/openwork","slug":"array-from-expects-an-array-string-map-set-or","errorCode":null,"errorMessage":"Array.from expects an array, string, Map, Set, or array-like value.","messagePattern":"Array\\.from expects an array, string, Map, Set, or array-like value\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/interpreter/runtime.ts","lineNumber":544,"sourceCode":"      }\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 &&\n        typeof source === \"object\" &&\n        typeof (source as { length?: unknown }).length === \"number\"\n      ) {\n        return Array.from(source as ArrayLike<unknown>)\n      }\n      throw new InterpreterRuntimeError(\"Array.from expects an array, string, Map, Set, or array-like value.\", node)\n    }\n    default:\n      throw new InterpreterRuntimeError(`Array.${name} is not available in CodeMode.`, node)\n  }\n}\n\nconst invokeGlobalMethod = (ref: GlobalMethodReference, args: Array<unknown>, node: AstNode): unknown => {\n  if (ref.namespace === \"console\")\n    throw new InterpreterRuntimeError(`console.${ref.name} is not available in CodeMode.`, node)\n  if (ref.namespace === \"Object\") return invokeObjectMethod(ref.name, args, node)\n  if (ref.namespace === \"Math\") return invokeMathMethod(ref.name, args, node)\n  if (ref.namespace === \"Array\") return invokeArrayStatic(ref.name, args, node)\n  if (ref.namespace === \"Number\") return invokeNumberStatic(ref.name, args, node)\n  if (ref.namespace === \"String\") return invokeStringStatic(ref.name, args, node)\n  if (ref.namespace === \"URL\") return invokeURLStatic(ref.name, args, node)\n  if (ref.namespace === \"Date\") {\n    if (!dateStatics.has(ref.name))\n      throw new InterpreterRuntimeError(`Date.${ref.name} is not available in CodeMode.`, node)","sourceCodeStart":526,"sourceCodeEnd":562,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/interpreter/runtime.ts#L526-L562","documentation":"When Array.from is called with a single argument, invokeArrayStatic validates the source: it accepts arrays, strings, Map, Set, or any object with a numeric length property. Anything else (plain objects without length, numbers, null, undefined) throws this error because the sandbox cannot safely iterate the value.","triggerScenarios":"Array.from(<unsupported value>) with one argument where the value is e.g. a plain object like {a:1}, a number, null/undefined, or a non-array-like custom object lacking a numeric length.","commonSituations":"Assuming Array.from converts object key/value pairs (it needs Object.entries first); passing a Map and expecting entries (supported here, but yields [key,value] pairs); defensive code passing possibly-null values into Array.from.","solutions":["Pass an array, string, Map, Set, or object with a numeric length property","For plain objects use Object.entries(obj) or Object.keys(obj) first (check Object method support)","Guard the input for null/undefined before calling Array.from"],"exampleFix":"// before\nconst arr = Array.from(obj);\n// after\nconst arr = Array.from(Object.entries(obj));","handlingStrategy":"validation","validationCode":"function isArrayFromSourceSafe(v) {\n  return Array.isArray(v) || typeof v === 'string' || v instanceof Map || v instanceof Set ||\n    (v !== null && typeof v === 'object' && typeof v.length === 'number');\n}","typeGuard":"function isArrayLike(v) { return v !== null && typeof v === 'object' && typeof v.length === 'number'; }","tryCatchPattern":null,"preventionTips":["Guard inputs for null/undefined before Array.from","Use Object.entries/Object.keys for plain objects","Only pass arrays, strings, Maps, Sets, or length-bearing objects"],"tags":["codemode","sandbox","array-from","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}