different-ai/openwork · error · InterpreterRuntimeError
Array.from expects an array, string, Map, Set, or array-like
Error message
Array.from expects an array, string, Map, Set, or array-like value.
What it means
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.
Source
Thrown at packages/codemode/src/interpreter/runtime.ts:544
}
// Map/Set materialize directly (the data checkpoint would serialize them to {}).
if (args[0] instanceof SandboxMap)
return Array.from((args[0] as SandboxMap).map.entries(), ([key, item]) => [key, item])
if (args[0] instanceof SandboxSet) return Array.from((args[0] as SandboxSet).set.values())
if (args[0] instanceof SandboxURLSearchParams) {
return Array.from(args[0].params.entries(), ([key, value]) => [key, value])
}
const source = boundedData(args[0], "Array.from input")
if (typeof source === "string") return Array.from(source)
if (Array.isArray(source)) return [...source]
if (
source !== null &&
typeof source === "object" &&
typeof (source as { length?: unknown }).length === "number"
) {
return Array.from(source as ArrayLike<unknown>)
}
throw new InterpreterRuntimeError("Array.from expects an array, string, Map, Set, or array-like value.", node)
}
default:
throw new InterpreterRuntimeError(`Array.${name} is not available in CodeMode.`, node)
}
}
const invokeGlobalMethod = (ref: GlobalMethodReference, args: Array<unknown>, node: AstNode): unknown => {
if (ref.namespace === "console")
throw new InterpreterRuntimeError(`console.${ref.name} is not available in CodeMode.`, node)
if (ref.namespace === "Object") return invokeObjectMethod(ref.name, args, node)
if (ref.namespace === "Math") return invokeMathMethod(ref.name, args, node)
if (ref.namespace === "Array") return invokeArrayStatic(ref.name, args, node)
if (ref.namespace === "Number") return invokeNumberStatic(ref.name, args, node)
if (ref.namespace === "String") return invokeStringStatic(ref.name, args, node)
if (ref.namespace === "URL") return invokeURLStatic(ref.name, args, node)
if (ref.namespace === "Date") {
if (!dateStatics.has(ref.name))
throw new InterpreterRuntimeError(`Date.${ref.name} is not available in CodeMode.`, node)View on GitHub (pinned to 2b7df46e8a)
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
Example fix
// before const arr = Array.from(obj); // after const arr = Array.from(Object.entries(obj));
Defensive patterns
Strategy: validation
Validate before calling
function isArrayFromSourceSafe(v) {
return Array.isArray(v) || typeof v === 'string' || v instanceof Map || v instanceof Set ||
(v !== null && typeof v === 'object' && typeof v.length === 'number');
} Type guard
function isArrayLike(v) { return v !== null && typeof v === 'object' && typeof v.length === 'number'; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Array.from(...) does not support a map function in CodeMode;
- String.${name} expects argument ${index + 1} to be a number.
- String.repeat expects a finite non-negative count.
- String method '${name}' is not available in CodeMode.
- Array.${name} is not available in CodeMode.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/83be134046eb006e.
Report an issue: GitHub.