{"record":{"id":"3e81a86fd956ddb4","repo":"different-ai/openwork","slug":"object-fromentries-expects-key-value-pairs","errorCode":null,"errorMessage":"Object.fromEntries expects [key, value] pairs.","messagePattern":"Object\\.fromEntries expects \\[key, value\\] pairs\\.","errorType":"exception","errorClass":"InterpreterRuntimeError","httpStatus":null,"severity":"error","filePath":"packages/codemode/src/stdlib/object.ts","lineNumber":69,"sourceCode":"    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":51,"sourceCodeEnd":78,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/packages/codemode/src/stdlib/object.ts#L51-L78","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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])"],"exampleFix":"// before\nconst record = Object.fromEntries(rows)\n// after\nconst record = Object.fromEntries(rows.map(r => [r.key, r.value]))","handlingStrategy":"type-guard","validationCode":"const isPair = (p: unknown): p is [string, unknown] => Array.isArray(p) && p.length >= 2\nconst safePairs = raw.filter(isPair)\nconst record = Object.fromEntries(safePairs)","typeGuard":"const isPair = (p: unknown): p is [unknown, unknown] => Array.isArray(p)","tryCatchPattern":"try {\n  return Object.fromEntries(pairs)\n} catch (e) {\n  if (e instanceof InterpreterRuntimeError && e.message.includes('expects [key, value] pairs')) {\n    return Object.fromEntries(pairs.filter((p) => Array.isArray(p)))\n  }\n  throw e\n}","preventionTips":["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])"],"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"}