different-ai/openwork · error · InterpreterRuntimeError
Object.${name} expects a data object.
Error message
Object.${name} expects a data object. What it means
The requireObject helper inside invokeObjectMethod validates that the first argument is a plain data object (not null, not an array, not a primitive, not a sandbox value). It throws this when Object.values, Object.entries, Object.hasOwn, or Object.fromEntries prechecks receive something else.
Source
Thrown at packages/codemode/src/stdlib/object.ts:14
import { type AstNode, InterpreterRuntimeError } from "../interpreter/model.js"
import { isBlockedMember } from "../tool-runtime.js"
import { isSandboxValue, SandboxMap, SandboxURLSearchParams } from "../values.js"
import { boundedData, coerceToString } from "./value.js"
export const objectStatics = new Set(["keys", "values", "entries", "hasOwn", "assign", "fromEntries"])
export const invokeObjectMethod = (name: string, args: Array<unknown>, node: AstNode): unknown => {
if (!objectStatics.has(name)) throw new InterpreterRuntimeError(`Object.${name} is not available in CodeMode.`, node)
const requireObject = (): Record<string, unknown> => {
const value = boundedData(args[0], `Object.${name} input`)
if (isSandboxValue(value)) return {}
if (value === null || typeof value !== "object" || Array.isArray(value)) {
throw new InterpreterRuntimeError(`Object.${name} expects a data object.`, node)
}
return value as Record<string, unknown>
}
const guardedSet = (out: Record<string, unknown>, key: string, item: unknown): void => {
if (isBlockedMember(key)) throw new InterpreterRuntimeError(`Property '${key}' is not available in CodeMode.`, node)
out[key] = item
}
switch (name) {
case "keys": {
const value = boundedData(args[0], "Object.keys input")
if (isSandboxValue(value)) return []
if (Array.isArray(value)) return Object.keys(value)
if (value === null || typeof value !== "object") {
throw new InterpreterRuntimeError("Object.keys expects a data object or array.", node)
}
return Object.keys(value)
}
case "values":View on GitHub (pinned to 2b7df46e8a)
Solutions
- Ensure the first argument is a plain object: wrap construction as data ?? {} before calling
- Convert arrays to keyed objects via Object.fromEntries(entries) when key/index mapping is needed
- Check API responses for null before passing to Object.values/entries
- Use Object.keys (which accepts arrays) instead of values/entries when the input may be an array
Example fix
// before
const counts = Object.entries(data)
// after
if (data && typeof data === 'object' && !Array.isArray(data)) {
const counts = Object.entries(data)
} Defensive patterns
Strategy: type-guard
Validate before calling
function assertPlainObject(v: unknown): asserts v is Record<string, unknown> {
if (v === null || typeof v !== 'object' || Array.isArray(v)) {
throw new Error('Object statics require a plain data object')
}
} Type guard
const isPlainObject = (v: unknown): v is Record<string, unknown> => v !== null && typeof v === 'object' && !Array.isArray(v)
Try / catch
try {
return Object.entries(input)
} catch (e) {
if (e instanceof InterpreterRuntimeError && e.message.includes('expects a data object')) {
return Object.entries(input && typeof input === 'object' && !Array.isArray(input) ? input : {})
}
throw e
} Prevention
- Coerce nullable API results with ?? {} before Object.values/entries
- Treat arrays separately — use Object.keys for array input
- Validate JSON.parse output shape before object statics
- Never pass primitives to Object statics in CodeMode
When it happens
Trigger: Object.values(null), Object.entries([1,2,3]) (array passed to entries/values), Object.hasOwn('str', 'k'), Object.values(42), or passing a sandbox opaque value that was mapped to {} and then a non-object second call path receives a primitive.
Common situations: Passing JSON.parse results that turned out to be null (JSON 'null'); passing arrays where the API demands a record; handling API responses that may be scalar in edge cases.
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.keys expects a data object or array.
- Object.assign expects data objects.
- Object.fromEntries expects an array of [key, value] pairs.
- 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/ca1df32d8fac1fdc.
Report an issue: GitHub.