different-ai/openwork · error · InterpreterRuntimeError

Array.from(...) does not support a map function in…

Error message

Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.

What it means

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.

Solutions

  1. Call Array.from with a single argument, then chain .map() on the result
  2. Build the values with a supported loop or Array constructor pattern
  3. If mapping a range, use a supported helper or a for loop pushing into an array

Example fix

// before
const squares = Array.from({length: 5}, (_, i) => i * i);
// after
const squares = Array.from({length: 5}).map((_, i) => i * i);
Defensive patterns

Strategy: validation

Validate before calling

// Reject two-argument Array.from before running CodeMode
if (/Array\.from\s*\([^)]*,/.test(code)) {
  throw new Error('CodeMode code uses Array.from with a map function; use .map() instead');
}

Type guard

function isSingleArgArrayFrom(call) { return call.arguments.length === 1; }

Prevention

When it happens

Trigger: 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()).

Common situations: 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.

Related errors


AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01). Data as JSON: /api/errors/0a2bfa9065d466cd. Report an issue: GitHub.

Appendix: source

Thrown at packages/codemode/src/interpreter/runtime.ts:520

    case "concat": {
      result = value.concat(...args.map((_, index) => str(index)))
      break
    }
    default:
      throw new InterpreterRuntimeError(`String method '${name}' is not available in CodeMode.`, node)
  }
  return boundedData(result, `String.${name} result`)
}

const invokeArrayStatic = (name: string, args: Array<unknown>, node: AstNode): unknown => {
  switch (name) {
    case "isArray":
      return Array.isArray(args[0])
    case "of":
      return [...args]
    case "from": {
      if (args.length > 1) {
        throw new InterpreterRuntimeError(
          "Array.from(...) does not support a map function in CodeMode; call .map() on the result instead.",
          node,
          "UnsupportedSyntax",
          [supportedSyntaxMessage],
        )
      }
      // 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 &&

View on GitHub (pinned to 2b7df46e8a)