Skip to content

Commit 4643d30

Browse files
committed
fix(scenarios): wrap hydration import + loop in try-catch (coderabbit minor)
1 parent c013879 commit 4643d30

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/cli/server-app.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,19 +487,28 @@ export function createMarsServer(options: CreateMarsServerOptions = {}): MarsSer
487487
}
488488
if (drafts.length === 0) return;
489489
console.log(`[scenarios] re-compiling ${drafts.length} persisted compiled draft(s) from disk…`);
490-
const { compileScenario } = await import('../engine/compiler/index.js');
491-
for (const { id, draft, meta } of drafts) {
492-
try {
493-
// Cache: true means we hit the local hook-source cache. With
494-
// a warm cache this is ~10ms per draft; with a cold cache the
495-
// hooks regenerate via LLM at the going rate.
496-
const compiled = await compileScenario(draft as Record<string, unknown>, { cache: true });
497-
customScenarioCatalog.set(compiled.id, { scenario: compiled, source: 'compiled' });
498-
compiledScenarioMeta.set(compiled.id, meta);
499-
console.log(`[scenarios] hydrated ${compiled.id} (${meta.compiledAt})`);
500-
} catch (err) {
501-
console.warn(`[scenarios] failed to re-compile persisted draft ${id}:`, err);
490+
// Wrap the dynamic import + per-draft loop in its own try-catch
491+
// so a module-resolution failure (deploy with broken compiler
492+
// bundle, fs hiccup) doesn't surface as an unhandled promise
493+
// rejection on the top-level IIFE — the catalog stays at builtins
494+
// only and the server keeps serving live runs.
495+
try {
496+
const { compileScenario } = await import('../engine/compiler/index.js');
497+
for (const { id, draft, meta } of drafts) {
498+
try {
499+
// Cache: true means we hit the local hook-source cache. With
500+
// a warm cache this is ~10ms per draft; with a cold cache the
501+
// hooks regenerate via LLM at the going rate.
502+
const compiled = await compileScenario(draft as Record<string, unknown>, { cache: true });
503+
customScenarioCatalog.set(compiled.id, { scenario: compiled, source: 'compiled' });
504+
compiledScenarioMeta.set(compiled.id, meta);
505+
console.log(`[scenarios] hydrated ${compiled.id} (${meta.compiledAt})`);
506+
} catch (err) {
507+
console.warn(`[scenarios] failed to re-compile persisted draft ${id}:`, err);
508+
}
502509
}
510+
} catch (err) {
511+
console.warn('[scenarios] compiler import failed during hydration:', err);
503512
}
504513
})();
505514

0 commit comments

Comments
 (0)