green: clean error for unknown game
Existence-check the spec.ts before importing — if it's missing, throw "unknown game: <id>" so callers see the identity, not Bun's module resolver internals. Existing valid imports go through the dynamic import unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 file changed · +4 −0
src/games.ts
+4
−0
| @@ -8,6 +8,10 @@ export interface Game { | ||
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | export async function loadGame(id: string): Promise<Game> { |
| 11 | + const file = Bun.file(`./content/games/${id}/spec.ts`); | |
| 12 | + if (!(await file.exists())) { | |
| 13 | + throw new Error(`unknown game: ${id}`); | |
| 14 | + } | |
| 11 | 15 | const mod = await import(`../content/games/${id}/spec.ts`); |
| 12 | 16 | return mod.spec as Game; |
| 13 | 17 | } |