{"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":"exception","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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/fetch/20_headers.js#L85-L121","documentation":"When a Headers object is initialized from an array (the sequence-of-pairs form), the Fetch spec's fill operation requires every entry to be exactly a [name, value] pair. fillHeaders in ext/fetch/20_headers.js throws this TypeError for any entry whose length is not 2.","triggerScenarios":"`new Headers([[\"a\"]])` or `new Headers([[\"a\", \"b\", \"c\"]])`; passing such arrays to `new Request(url, { headers })`, `new Response(body, { headers })`, or `fetch(url, { headers })`; entries built from Map.values() where values are 3-element arrays.","commonSituations":"Header tuples from JSON/config that carry a third element (e.g. a comment); passing [key, value, flag] triples from an internal header model; converting an object-of-objects into nested arrays.","solutions":["Ensure every entry is exactly `[name, value]`","Prefer the record form when names are static: `new Headers({ \"x\": \"y\" })`","Normalize before constructing: `pairs.map(([k, v]) => [k, v])`"],"exampleFix":"// before\nconst h = new Headers([[\"content-type\", \"text/html\", \"charset=utf-8\"]]);\n\n// after\nconst h = new Headers([[\"content-type\", \"text/html; charset=utf-8\"]]);","handlingStrategy":"validation","validationCode":"function isValidHeaderPairs(init: unknown): boolean {\n  return Array.isArray(init) && init.every(\n    (e) => Array.isArray(e) && e.length === 2,\n  );\n}","typeGuard":"function isHeaderPair(e: unknown): e is [string, string] {\n  return Array.isArray(e) && e.length === 2 &&\n    typeof e[0] === \"string\" && typeof e[1] === \"string\";\n}","tryCatchPattern":null,"preventionTips":["Pass only [name, value] pairs in array form","Prefer the record form { name: value } for static headers","Map external header tuples down to two elements before constructing"],"tags":["fetch","headers","validation","web-api"],"backgroundTag":"invalid-headers-init","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}