different-ai/openwork · error · InterpreterRuntimeError
Object.fromEntries expects an array of [key, value] pairs.
Error message
Object.fromEntries expects an array of [key, value] pairs.
What it means
Object.fromEntries in CodeMode requires its argument to be an array of [key, value] pairs (or a SandboxURLSearchParams). If the top-level argument is not an array, invokeObjectMethod throws this message before inspecting individual pairs.
Source
Thrown at packages/codemode/src/stdlib/object.ts:64
}
for (const [key, item] of Object.entries(value)) guardedSet(out, key, item)
}
return out
}
case "fromEntries": {
if (args[0] instanceof SandboxMap) {
const out: Record<string, unknown> = Object.create(null)
for (const [key, item] of args[0].map.entries()) guardedSet(out, coerceToString(key), item)
return out
}
if (args[0] instanceof SandboxURLSearchParams) {
const out: Record<string, unknown> = Object.create(null)
for (const [key, value] of args[0].params.entries()) guardedSet(out, key, value)
return out
}
const pairs = boundedData(args[0], "Object.fromEntries input")
if (!Array.isArray(pairs)) {
throw new InterpreterRuntimeError("Object.fromEntries expects an array of [key, value] pairs.", node)
}
const out: Record<string, unknown> = Object.create(null)
for (const pair of pairs) {
if (!Array.isArray(pair)) {
throw new InterpreterRuntimeError("Object.fromEntries expects [key, value] pairs.", node)
}
guardedSet(out, String(pair[0]), pair[1])
}
return out
}
}
throw new InterpreterRuntimeError(`Object.${name} is not available in CodeMode.`, node)
}
View on GitHub (pinned to 2b7df46e8a)
Solutions
- Pass an array of pairs: Object.fromEntries(Object.entries(obj)) when converting an object
- Parse JSON strings first: Object.fromEntries(JSON.parse(serializedPairs))
- Default the argument: Object.fromEntries(pairs ?? [])
- If you have a Map-like sandbox value, use its .entries()/params API as the branch supports URLSearchParams-style inputs
Example fix
// before const record = Object.fromEntries(myMapLike) // after const record = Object.fromEntries(Object.entries(myMapLike))
Defensive patterns
Strategy: type-guard
Validate before calling
function assertPairs(v: unknown): asserts v is Array<Array<unknown>> {
if (!Array.isArray(v)) throw new Error('Object.fromEntries needs an array of pairs')
}
const pairs = raw ?? [] Type guard
const isPairArray = (v: unknown): v is Array<[string, unknown]> => Array.isArray(v) && v.every((p) => Array.isArray(p))
Try / catch
try {
return Object.fromEntries(input)
} catch (e) {
if (e instanceof InterpreterRuntimeError && e.message.includes('expects an array of [key, value] pairs')) {
return Object.fromEntries(Object.entries(input as Record<string, unknown>))
}
throw e
} Prevention
- Use Object.entries(obj) when converting an object to a record
- Parse JSON strings before fromEntries
- Default undefined inputs to []
- Map {key,value} object rows to tuples first
When it happens
Trigger: Object.fromEntries({a:1}) (object instead of array), Object.fromEntries(map) using a plain object where a Map was intended, Object.fromEntries(null/undefined), Object.fromEntries(entriesString) where a serialized JSON string was never parsed.
Common situations: Converting a Map-like object to a record without calling .entries() first; receiving Object.entries-style arrays as JSON strings from an API; passing undefined when the upstream variable failed to populate.
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
- Object.${name} expects a data object.
- Object.keys expects a data object or array.
- Object.assign expects data objects.
- Object.fromEntries expects [key, value] pairs.
- String.${name} expects argument ${index + 1} to be a number.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/2d4b6f87e6eec260.
Report an issue: GitHub.