oven-sh/bun · error · Error
${name}: ${entries.length} entries exceed u16 indexOf range
Error message
${name}: ${entries.length} entries exceed u16 indexOf range What it means
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.
Source
Thrown at src/codegen/generate-string-map.ts:253
}
seenCi.add(lk);
}
}
const kvs: Array<readonly [Buffer, string]> = entries.map(([k, v]) => [Buffer.from(k, "utf8"), emitValue(v)]);
const out: string[] = [];
if (doc) for (const line of doc.split("\n")) out.push(`/// ${line}`.trimEnd());
emitLookup(out, name, valueTy, kvs, { ci: false });
if (emitCaseInsensitive) {
out.push(``);
emitLookup(out, `${name}_ignore_ascii_case`, valueTy, kvs, { ci: true });
}
if (emitIndexOf) {
// Index in *declaration order* — same as `<NAME>_KEYS` so
// `KEYS[index_of(k).unwrap()]` round-trips. u16 is plenty (asserted).
if (entries.length > 0xffff) throw new Error(`${name}: ${entries.length} entries exceed u16 indexOf range`);
const idxKvs: Array<readonly [Buffer, string]> = entries.map(([k], i) => [Buffer.from(k, "utf8"), `${i}u16`]);
out.push(``);
emitLookup(out, `${name}_index`, `u16`, idxKvs, { ci: false });
}
if (emitKeys || emitIndexOf) {
out.push(``);
out.push(`pub static ${name.toUpperCase()}_KEYS: &[&[u8]] = &[`);
for (const [k] of entries) out.push(` ${rsBytes(k)},`);
out.push(`];`);
}
return out.join("\n");
}
export function generateStringMaps(
specs: StringMapSpec<unknown> | StringMapSpec<unknown>[],
inputPath: string,View on GitHub (pinned to 8c5296ac45)
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.
Example fix
// before
export default { name: "BigMap", emitIndexOf: true, entries: hugeList };
// after
export default { name: "BigMap", emitIndexOf: false, entries: hugeList }; Defensive patterns
Strategy: validation
Validate before calling
function assertIndexOfFits(name, entries, emitIndexOf) {
if (emitIndexOf && entries.length > 0xffff) {
throw new Error(`${name}: ${entries.length} entries > u16; disable emitIndexOf or split the map`);
}
} Prevention
- 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.
When it happens
Trigger: A spec with `emitIndexOf: true` (or `emitKeys`, which pairs with it) whose `entries.length` exceeds 65535.
Common situations: Importing a very large generated table (e.g. thousands of ICU/mime/database identifiers) into a string-map with indexOf enabled.
Related errors
- generate-string-map: duplicate key ${JSON.stringify(k)} in $
- generate-string-map: ${name}: emitCaseInsensitive requires A
- generate-string-map: ${name}: keys ${JSON.stringify(k)} coll
- ${input}: missing default export
- file did not exist after write: ${outputPath}
AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16).
Data as JSON: /api/errors/85bde519d6f8813f.
Report an issue: GitHub.