{"record":{"id":"2d4b6f87e6eec260","repo":"different-ai/openwork","slug":"object-fromentries-expects-an-array-of-key-value","errorCode":null,"errorMessage":"Object.fromEntries expects an array of [key, value] pairs.","messagePattern":"Object\\.fromEntries expects an array of \\[key, value\\] pairs\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/object.ts","lineNumber":64,"sourceCode":"        }\n        for (const [key, item] of Object.entries(value)) guardedSet(out, key, item)\n      }\n      return out\n    }\n    case \"fromEntries\": {\n      if (args[0] instanceof SandboxMap) {\n        const out: Record<string, unknown> = Object.create(null)\n        for (const [key, item] of args[0].map.entries()) guardedSet(out, coerceToString(key), item)\n        return out\n      }\n      if (args[0] instanceof SandboxURLSearchParams) {\n        const out: Record<string, unknown> = Object.create(null)\n        for (const [key, value] of args[0].params.entries()) guardedSet(out, key, value)\n        return out\n      }\n      const pairs = boundedData(args[0], \"Object.fromEntries input\")\n      if (!Array.isArray(pairs)) {\n        throw new InterpreterRuntimeError(\"Object.fromEntries expects an array of [key, value] pairs.\", node)\n      }\n      const out: Record<string, unknown> = Object.create(null)\n      for (const pair of pairs) {\n        if (!Array.isArray(pair)) {\n          throw new InterpreterRuntimeError(\"Object.fromEntries expects [key, value] pairs.\", node)\n        }\n        guardedSet(out, String(pair[0]), pair[1])\n      }\n      return out\n    }\n  }\n  throw new InterpreterRuntimeError(`Object.${name} is not available in CodeMode.`, node)\n}\n","sourceCodeStart":46,"sourceCodeEnd":78,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/object.ts#L46-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst record = Object.fromEntries(myMapLike)\n// after\nconst record = Object.fromEntries(Object.entries(myMapLike))","handlingStrategy":"type-guard","validationCode":"function assertPairs(v: unknown): asserts v is Array<Array<unknown>> {\n  if (!Array.isArray(v)) throw new Error('Object.fromEntries needs an array of pairs')\n}\nconst pairs = raw ?? []","typeGuard":"const isPairArray = (v: unknown): v is Array<[string, unknown]> =>\n  Array.isArray(v) && v.every((p) => Array.isArray(p))","tryCatchPattern":"try {\n  return Object.fromEntries(input)\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && e.message.includes('expects an array of [key, value] pairs')) {\n    return Object.fromEntries(Object.entries(input as Record<string, unknown>))\n  }\n  throw e\n}","preventionTips":["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"],"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"}