{"record":{"id":"3896444072d37167","repo":"denoland/deno","slug":"invalid-header-length-must-be-2-but-is-header","errorCode":null,"errorMessage":"Invalid header: length must be 2, but is ${header.length}","messagePattern":"Invalid header: length must be 2, but is (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/20_headers.js","lineNumber":103,"sourceCode":"\n/**\n * @param {string} potentialValue\n * @returns {string}\n */\nfunction normalizeHeaderValue(potentialValue) {\n  return httpTrim(potentialValue);\n}\n\n/**\n * @param {Headers} headers\n * @param {HeadersInit} object\n */\nfunction fillHeaders(headers, object) {\n  if (ArrayIsArray(object)) {\n    for (let i = 0; i < object.length; ++i) {\n      const header = object[i];\n      if (header.length !== 2) {\n        throw new TypeError(\n          `Invalid header: length must be 2, but is ${header.length}`,\n        );\n      }\n      appendHeader(headers, header[0], header[1]);\n    }\n  } else {\n    for (const key in object) {\n      if (!ObjectHasOwn(object, key)) {\n        continue;\n      }\n      appendHeader(headers, key, object[key]);\n    }\n  }\n}\n\nfunction checkForInvalidValueChars(value) {\n  for (let i = 0; i < value.length; i++) {\n    const c = StringPrototypeCharCodeAt(value, i);","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/fetch/20_headers.js#L85-L121","documentation":"fillHeaders processes a HeadersInit given as an array of pairs; every entry must have length exactly 2 ([name, value]). It runs on the Request constructor's init.headers path (ext/fetch/23_request.js) and for EventSource initial headers, so malformed pairs surface from new Request(url, { headers: [...] }).","triggerScenarios":"new Request(url, { headers: [['x']] }) or { headers: [['a', 'b', 'c']] } — each inner array must contain exactly a name and a value.","commonSituations":"Building header pairs dynamically and pushing wrong-shaped rows; splitting a raw header block into nested arrays with an extra field.","solutions":["Emit exactly [name, value] pairs.","Prefer the object form { 'content-type': 'text/plain' } when the data is not already pairs."],"exampleFix":"// before\nnew Request(url, { headers: [['accept', 'text/html', 'utf-8']] });\n// after\nnew Request(url, { headers: [['accept', 'text/html']] });","handlingStrategy":"type-guard","validationCode":"if (Array.isArray(headersInit) && !headersInit.every((h) => Array.isArray(h) && h.length === 2)) {\n  throw new Error('headers array must contain [name, value] pairs');\n}\nnew Request(url, { headers: headersInit });","typeGuard":"function isHeaderPairs(v: unknown): v is [string, string][] {\n  return Array.isArray(v) &&\n    v.every((e) => Array.isArray(e) && e.length === 2);\n}","tryCatchPattern":null,"preventionTips":["Type header arrays as [string, string][] (or HeadersInit) so wrong shapes fail at compile time.","Build pairs in one place and assert the shape before passing to Request/EventSource."],"tags":["headers","fetch","request","validation"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}