syntaxai/tdd.md · commit 6ba2976

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]>
author
syntaxai <[email protected]>
date
2026-05-03 16:35:05 +01:00
parent
3b30eb5
commit
6ba2976e1b5da7d1f3fd5819d35386e165f78682

1 file changed · +4 −0

modified src/games.ts +4 −0
@@ -8,6 +8,10 @@ export interface Game {
88 }
99
1010 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+ }
1115 const mod = await import(`../content/games/${id}/spec.ts`);
1216 return mod.spec as Game;
1317 }