oven-sh/bun · error · Error

usage: bun src/codegen/generate-string-map.ts <input.string-

Error message

usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>

What it means

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.

Source

Thrown at src/codegen/generate-string-map.ts:289

  inputPath: string,
): string {
  const arr = Array.isArray(specs) ? specs : [specs];
  const rel = path.relative(process.cwd(), inputPath).replaceAll("\\", "/");
  // No `#![allow]` — this is `include!`d, and inner attributes aren't legal
  // mid-module. Per-item allows are emitted where needed instead.
  return [
    `// Generated by src/codegen/generate-string-map.ts from ${rel} — do not edit.`,
    ``,
    ...arr.map(s => buildOne(s)),
    ``,
  ].join("\n\n");
}

// ── CLI ─────────────────────────────────────────────────────────────────────
if (import.meta.main) {
  const [, , input, output] = process.argv;
  if (!input || !output) {
    throw new Error("usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>");
  }
  const mod = await import(path.resolve(input));
  const specs = mod.default as StringMapSpec<unknown> | StringMapSpec<unknown>[];
  if (!specs) throw new Error(`${input}: missing default export`);
  writeIfNotChanged(output, generateStringMaps(specs, input));
}

View on GitHub (pinned to 8c5296ac45)

Solutions

  1. Pass both arguments: the .string-map.ts input and the .rs output path.
  2. If calling from a script, quote and default the arguments (e.g. `out="${OUT:-src/gen/table.rs}"`).

Example fix

# before
bun src/codegen/generate-string-map.ts src/js_parser/defines_table.string-map.ts

# after
bun src/codegen/generate-string-map.ts src/js_parser/defines_table.string-map.ts src/js_parser/defines_table.generated.rs
Defensive patterns

Strategy: validation

Validate before calling

if (import.meta.main) {
  const [, , input, output] = process.argv;
  if (!input || !output) {
    console.error("usage: bun src/codegen/generate-string-map.ts <input.string-map.ts> <out.rs>");
    process.exit(2);
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: Wiring the generator into a new package.json script and forgetting the output path; passing an empty string because a shell variable was unset.

Related errors


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/25130628fca887b4. Report an issue: GitHub.