{"record":{"id":"58b1f0147a7b05d9","repo":"zloirock/core-js","slug":"expected-sequence-with-length-2","errorCode":null,"errorMessage":"Expected sequence with length 2","messagePattern":"Expected sequence with length 2","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/web.url-search-params.constructor.js","lineNumber":138,"sourceCode":"    this.url = url;\n    this.update();\n  },\n  parseObject: function (object) {\n    var entries = this.entries;\n    var iteratorMethod = getIteratorMethod(object);\n    var iterator, next, step, entryIterator, entryNext, first, second;\n\n    if (iteratorMethod) {\n      iterator = getIterator(object, iteratorMethod);\n      next = iterator.next;\n      while (!(step = call(next, iterator)).done) {\n        entryIterator = getIterator(anObject(step.value));\n        entryNext = entryIterator.next;\n        if (\n          (first = call(entryNext, entryIterator)).done ||\n          (second = call(entryNext, entryIterator)).done ||\n          !call(entryNext, entryIterator).done\n        ) throw new TypeError('Expected sequence with length 2');\n        push(entries, { key: $toString(first.value), value: $toString(second.value) });\n      }\n    } else for (var key in object) if (hasOwn(object, key)) {\n      push(entries, { key: key, value: $toString(object[key]) });\n    }\n  },\n  parseQuery: function (query) {\n    if (query) {\n      var entries = this.entries;\n      var attributes = split(query, '&');\n      var index = 0;\n      var attribute, entry;\n      while (index < attributes.length) {\n        attribute = attributes[index++];\n        if (attribute.length) {\n          entry = split(attribute, '=');\n          push(entries, {\n            key: decodeQueryComponent(shift(entry)),","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/web.url-search-params.constructor.js#L120-L156","documentation":"TypeError thrown by the URLSearchParams polyfill constructor when initializing from a sequence-of-sequences: each entry must be an iterable yielding exactly two values (key, value). The code pulls three iterator steps and requires the first two done===false and the third done===true; otherwise 'Expected sequence with length 2' is thrown.","triggerScenarios":"new URLSearchParams([[k]], [[k,v,extra]] or new URLSearchParams([['a','b','c']]) — any inner entry whose iterator yields fewer than 2 or more than 2 values.","commonSituations":"Passing Object.entries-like arrays that contain 3-element rows; spreading a Map with tuple-ish arrays of wrong arity; a row that is a string of length != 2 (iterating a string yields chars); mistyped rows after data transformation.","solutions":["Ensure every entry is a [key, value] pair of exactly two elements","Map/normalize rows: entries.map(([k, v]) => [k, v]) or entries.map(r => [r[0], r[1]])","Use an object or a Map instead of raw sequences when arity is uncertain"],"exampleFix":"// before\nnew URLSearchParams([['a', 'b', 'extra']]); // TypeError: Expected sequence with length 2\n// after\nnew URLSearchParams([['a', 'b']]);","handlingStrategy":"validation","validationCode":"function toPairs(input) {\n  if (Array.isArray(input)) return input.map(r => [String(r[0]), String(r[1])]);\n  if (input instanceof Map) return [...input].map(([k, v]) => [String(k), String(v)]);\n  return Object.entries(input);\n}\nconst params = new URLSearchParams(toPairs(raw));","typeGuard":"const isPair = (e) =>\n  e != null && typeof e[Symbol.iterator] === 'function' &&\n  [...e].length === 2;","tryCatchPattern":"try {\n  p = new URLSearchParams(seq);\n} catch (e) {\n  if (e instanceof TypeError && /Expected sequence with length 2/.test(e.message)) {\n    p = new URLSearchParams(seq.map(r => [r[0], r[1]]));\n  } else throw e;\n}","preventionTips":["Ensure each sequence entry yields exactly two values","Normalize rows via map(([k,v]) => [k,v]) before constructing","Prefer objects or Maps over raw sequences for string data","Beware string rows — iterating a string yields characters"],"tags":["urlsearchparams","sequence","typeerror","polyfill"],"backgroundTag":"invalid-sequence-entry","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}