different-ai/openwork · error · InterpreterRuntimeError
Object.fromEntries expects [key, value] pairs.
Error message
Object.fromEntries expects [key, value] pairs.
What it means
After confirming the fromEntries argument is an array, CodeMode validates each element is itself an array ([key, value] pair). A non-array element throws this second, more specific message.
Source
Thrown at packages/codemode/src/stdlib/object.ts:69
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
- Ensure each element is a 2-tuple: pairs.map(p => Array.isArray(p) ? p : [p.key, p.value])
- If you only have keys, build pairs: Object.keys(o).map(k => [k, o[k]])
- Filter malformed rows first: pairs.filter(p => Array.isArray(p) && p.length >= 2)
- Convert {key,value} object rows with rows.map(r => [r.key, r.value])
Example fix
// before const record = Object.fromEntries(rows) // after const record = Object.fromEntries(rows.map(r => [r.key, r.value]))
Defensive patterns
Strategy: type-guard
Validate before calling
const isPair = (p: unknown): p is [string, unknown] => Array.isArray(p) && p.length >= 2 const safePairs = raw.filter(isPair) const record = Object.fromEntries(safePairs)
Type guard
const isPair = (p: unknown): p is [unknown, unknown] => Array.isArray(p)
Try / catch
try {
return Object.fromEntries(pairs)
} catch (e) {
if (e instanceof InterpreterRuntimeError && e.message.includes('expects [key, value] pairs')) {
return Object.fromEntries(pairs.filter((p) => Array.isArray(p)))
}
throw e
} Prevention
- Validate every pair is a 2-element array before fromEntries
- Build pairs with explicit tuples, not split strings
- Filter null holes out of pair arrays
- Convert {key,value} rows with map(r => [r.key, r.value])
When it happens
Trigger: Object.fromEntries(['ab', 'cd']) (strings not split into pairs), Object.fromEntries([{key:'a', value:1}]) (objects instead of tuples), Object.fromEntries(Object.keys(o)) forgetting values, pairs built with nulls in between.
Common situations: Hand-building pair arrays where one row was a string due to a split() miss; schema drift from an API returning {key,value} objects; filtering that left a null hole in the pairs array.
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 an array of [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/3e81a86fd956ddb4.
Report an issue: GitHub.