{"record":{"id":"ca1df32d8fac1fdc","repo":"different-ai/openwork","slug":"object-name-expects-a-data-object","errorCode":null,"errorMessage":"Object.${name} expects a data object.","messagePattern":"Object\\.(.+?) expects a data object\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/object.ts","lineNumber":14,"sourceCode":"import { type AstNode, InterpreterRuntimeError } from \"../interpreter/model.js\"\nimport { isBlockedMember } from \"../tool-runtime.js\"\nimport { isSandboxValue, SandboxMap, SandboxURLSearchParams } from \"../values.js\"\nimport { boundedData, coerceToString } from \"./value.js\"\n\nexport const objectStatics = new Set([\"keys\", \"values\", \"entries\", \"hasOwn\", \"assign\", \"fromEntries\"])\n\nexport const invokeObjectMethod = (name: string, args: Array<unknown>, node: AstNode): unknown => {\n  if (!objectStatics.has(name)) throw new InterpreterRuntimeError(`Object.${name} is not available in CodeMode.`, node)\n  const requireObject = (): Record<string, unknown> => {\n    const value = boundedData(args[0], `Object.${name} input`)\n    if (isSandboxValue(value)) return {}\n    if (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n      throw new InterpreterRuntimeError(`Object.${name} expects a data object.`, node)\n    }\n    return value as Record<string, unknown>\n  }\n  const guardedSet = (out: Record<string, unknown>, key: string, item: unknown): void => {\n    if (isBlockedMember(key)) throw new InterpreterRuntimeError(`Property '${key}' is not available in CodeMode.`, node)\n    out[key] = item\n  }\n  switch (name) {\n    case \"keys\": {\n      const value = boundedData(args[0], \"Object.keys input\")\n      if (isSandboxValue(value)) return []\n      if (Array.isArray(value)) return Object.keys(value)\n      if (value === null || typeof value !== \"object\") {\n        throw new InterpreterRuntimeError(\"Object.keys expects a data object or array.\", node)\n      }\n      return Object.keys(value)\n    }\n    case \"values\":","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/object.ts#L1-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst counts = Object.entries(data)\n// after\nif (data && typeof data === 'object' && !Array.isArray(data)) {\n  const counts = Object.entries(data)\n}","handlingStrategy":"type-guard","validationCode":"function assertPlainObject(v: unknown): asserts v is Record<string, unknown> {\n  if (v === null || typeof v !== 'object' || Array.isArray(v)) {\n    throw new Error('Object statics require a plain data object')\n  }\n}","typeGuard":"const isPlainObject = (v: unknown): v is Record<string, unknown> =>\n  v !== null && typeof v === 'object' && !Array.isArray(v)","tryCatchPattern":"try {\n  return Object.entries(input)\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && e.message.includes('expects a data object')) {\n    return Object.entries(input && typeof input === 'object' && !Array.isArray(input) ? input : {})\n  }\n  throw e\n}","preventionTips":["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"],"tags":["codemode","type-error","object","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}