{"record":{"id":"25130628fca887b4","repo":"oven-sh/bun","slug":"usage-bun-src-codegen-generate-string-map-ts-inp","errorCode":null,"errorMessage":"usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>","messagePattern":"usage: bun src/codegen/generate-string-map\\.ts <input\\.string-map\\.ts> <out\\.rs>","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/codegen/generate-string-map.ts","lineNumber":289,"sourceCode":"  inputPath: string,\n): string {\n  const arr = Array.isArray(specs) ? specs : [specs];\n  const rel = path.relative(process.cwd(), inputPath).replaceAll(\"\\\\\", \"/\");\n  // No `#![allow]` — this is `include!`d, and inner attributes aren't legal\n  // mid-module. Per-item allows are emitted where needed instead.\n  return [\n    `// Generated by src/codegen/generate-string-map.ts from ${rel} — do not edit.`,\n    ``,\n    ...arr.map(s => buildOne(s)),\n    ``,\n  ].join(\"\\n\\n\");\n}\n\n// ── CLI ─────────────────────────────────────────────────────────────────────\nif (import.meta.main) {\n  const [, , input, output] = process.argv;\n  if (!input || !output) {\n    throw new Error(\"usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>\");\n  }\n  const mod = await import(path.resolve(input));\n  const specs = mod.default as StringMapSpec<unknown> | StringMapSpec<unknown>[];\n  if (!specs) throw new Error(`${input}: missing default export`);\n  writeIfNotChanged(output, generateStringMaps(specs, input));\n}\n","sourceCodeStart":271,"sourceCodeEnd":296,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/generate-string-map.ts#L271-L296","documentation":"generate-string-map.ts is also a CLI: `bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>`. It requires exactly two positional arguments — the spec module to import and the Rust file to write — and throws this usage error when either is missing.","triggerScenarios":"Invoking the script with zero or one argument (e.g. `bun src/codegen/generate-string-map.ts spec.file` or from a build script that passes an undefined output path).","commonSituations":"Wiring the generator into a new package.json script and forgetting the output path; passing an empty string because a shell variable was unset.","solutions":["Pass both arguments: the .string-map.ts input and the .rs output path.","If calling from a script, quote and default the arguments (e.g. `out=\"${OUT:-src/gen/table.rs}\"`)."],"exampleFix":"# before\nbun src/codegen/generate-string-map.ts src/js_parser/defines_table.string-map.ts\n\n# after\nbun src/codegen/generate-string-map.ts src/js_parser/defines_table.string-map.ts src/js_parser/defines_table.generated.rs","handlingStrategy":"validation","validationCode":"if (import.meta.main) {\n  const [, , input, output] = process.argv;\n  if (!input || !output) {\n    console.error(\"usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>\");\n    process.exit(2);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap generator invocations in a checked npm script so argument typos fail loudly.","Use `set -u` (or a TS arg parser) in build scripts to catch unset variables before they become empty args."],"tags":["codegen","cli","usage"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}