{"record":{"id":"85bde519d6f8813f","repo":"oven-sh/bun","slug":"name-entries-length-entries-exceed-u16-inde","errorCode":null,"errorMessage":"${name}: ${entries.length} entries exceed u16 indexOf range","messagePattern":"(.+?): (.+?) entries exceed u16 indexOf range","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-string-map.ts","lineNumber":253,"sourceCode":"      }\n      seenCi.add(lk);\n    }\n  }\n\n  const kvs: Array<readonly [Buffer, string]> = entries.map(([k, v]) => [Buffer.from(k, \"utf8\"), emitValue(v)]);\n  const out: string[] = [];\n  if (doc) for (const line of doc.split(\"\\n\")) out.push(`/// ${line}`.trimEnd());\n  emitLookup(out, name, valueTy, kvs, { ci: false });\n\n  if (emitCaseInsensitive) {\n    out.push(``);\n    emitLookup(out, `${name}_ignore_ascii_case`, valueTy, kvs, { ci: true });\n  }\n\n  if (emitIndexOf) {\n    // Index in *declaration order* — same as `<NAME>_KEYS` so\n    // `KEYS[index_of(k).unwrap()]` round-trips. u16 is plenty (asserted).\n    if (entries.length > 0xffff) throw new Error(`${name}: ${entries.length} entries exceed u16 indexOf range`);\n    const idxKvs: Array<readonly [Buffer, string]> = entries.map(([k], i) => [Buffer.from(k, \"utf8\"), `${i}u16`]);\n    out.push(``);\n    emitLookup(out, `${name}_index`, `u16`, idxKvs, { ci: false });\n  }\n\n  if (emitKeys || emitIndexOf) {\n    out.push(``);\n    out.push(`pub static ${name.toUpperCase()}_KEYS: &[&[u8]] = &[`);\n    for (const [k] of entries) out.push(`    ${rsBytes(k)},`);\n    out.push(`];`);\n  }\n\n  return out.join(\"\\n\");\n}\n\nexport function generateStringMaps(\n  specs: StringMapSpec<unknown> | StringMapSpec<unknown>[],\n  inputPath: string,","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-string-map.ts#L235-L271","documentation":"When a spec sets `emitIndexOf`, the generator emits a `<name>_index` lookup returning `u16` indices so `KEYS[index_of(k).unwrap()]` round-trips in declaration order. There are only 65536 u16 values, so more than 0xffff entries cannot be represented and the generator aborts.","triggerScenarios":"A spec with `emitIndexOf: true` (or `emitKeys`, which pairs with it) whose `entries.length` exceeds 65535.","commonSituations":"Importing a very large generated table (e.g. thousands of ICU/mime/database identifiers) into a string-map with indexOf enabled.","solutions":["Set `emitIndexOf: false` (and `emitKeys: false` if unused) so no u16 index table is generated.","Split the entries into several smaller map specs, each under the limit.","If the index is essential, change the generator to emit `u32` indices and update the Rust consumer accordingly."],"exampleFix":"// before\nexport default { name: \"BigMap\", emitIndexOf: true, entries: hugeList };\n\n// after\nexport default { name: \"BigMap\", emitIndexOf: false, entries: hugeList };","handlingStrategy":"validation","validationCode":"function assertIndexOfFits(name, entries, emitIndexOf) {\n  if (emitIndexOf && entries.length > 0xffff) {\n    throw new Error(`${name}: ${entries.length} entries > u16; disable emitIndexOf or split the map`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only enable emitIndexOf when something actually consumes KEY/index round-tripping.","If a table can grow unboundedly (generated from external data), avoid indexOf or budget for splitting."],"tags":["codegen","string-map","u16","limits"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}