fix: harden core build system against silent failures

- Wrap rebuild() in try/finally to guarantee mutex release (prevents deadlock)
- Surface rebuild errors via .catch() instead of discarding with void
- Add null checks for vfile.data.relativePath (prevents crash on virtual files)
- Add try-finally for worker pool cleanup in parse.ts (prevents thread leaks)
- Remove process.exit(1) from parse error handler (let errors propagate)
- Add per-emitter error handling in emit phase with degraded-build warning
- Replace unsafe Map.get()! assertions with null-checked access in config-loader
This commit is contained in:
saberzero1
2026-05-24 17:09:46 +02:00
parent 17aa8ab233
commit caa55037f7
4 changed files with 192 additions and 160 deletions
+12 -1
View File
@@ -78,12 +78,23 @@ export async function emitContent(ctx: BuildCtx, content: ProcessedContent[]) {
const otherEmitters = cfg.plugins.emitters.filter(
(e) => e.name !== "PageTypeDispatcher" && e.name !== "ComponentResources",
)
let emitErrors = 0
const counts = await Promise.all(
otherEmitters.map((emitter) =>
runEmitter(emitter, ctx, contentWithVirtual, staticResources, log),
runEmitter(emitter, ctx, contentWithVirtual, staticResources, log).catch((err) => {
emitErrors++
console.error(`Emitter "${emitter.name}" failed:`, err.message ?? err)
return 0
}),
),
)
emittedFiles += counts.reduce((sum, c) => sum + c, 0)
if (emitErrors > 0) {
console.warn(
`\nBuild completed with ${emitErrors} emitter failure(s). Output may be incomplete.`,
)
}
log.end(`Emitted ${emittedFiles} files to \`${argv.output}\` in ${perf.timeSince()}`)
}