Repository navigation
feat(flame): fail the build when a plugin hook throws - #485
Conversation
An error in onStart, onLoad, transformFrontmatter, transformHtml or onEnd was logged and the build exited with code 0, shipping pages without that hook's work. An onLoad plugin that removes internal content would publish the unchanged source when it threw.
BuildPluginBuilder takes { strict }. In strict mode each execution hook rethrows the first error as "[plugin] <hook> error: <message>" with the original as cause; page hooks name the source file. flame build (build.ts and build.impl.ts) sets strict, so the build exits with code 1: onStart and onLoad stop it before pages are written, a failing transformFrontmatter or transformHtml leaves that page unwritten, and onEnd fails after the pages. flame dev keeps the lenient default and still logs and carries on, and handleRequest always logs since it only runs in dev.
The plugin guide's Error Isolation section becomes Error Handling, with separate flame build and flame dev columns.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
ℹ️ No blocking issues — one small docs inaccuracy inline.
Reviewed changes
Reviewed in senior mode, since this touches plugin execution in the flame build pipeline. I traced every strict hook error through build.ts and build.impl.ts, and through both deploy entrypoints, to the exit code. Bun and Node/Deno behave the same, and the dev server stays lenient. The touched tests pass locally (plugin-integration.test.ts + plugin.test.ts, 73 tests), and tsc --noEmit and oxlint report no problems. Verdict: READY WITH MINOR FIXES.
BuildPluginBuilderOptions.strict: the newhookFailed()helper keeps the five catch blocks DRY. In strict mode it rethrows[plugin] <hook> error: …with the original error ascause.- Strict in
flame buildonly: both build entrypoints pass{ strict: true }.server.tsandserver.impl.tskeep the default.deploy.tschecks the child's exit code anddeploy.shared.tsgoes throughrunBuildCli(), so a failing hook also stopsflame deploy. - Error propagation: a failing docs page hook is caught for that page and counted in
errors, which gives exit 1. A prepassonLoaderror aborts the build throughPromise.all.onStartandonEnderrors reach the top-levelBuild failedhandler. Because the build re-renders every page when plugins are configured (the!builderguards), skippingwriteCache()cannot hide a failure on the next run. - Docs and changeset: the new "Error Handling" table, the JSDoc updates and the
minorchangeset match how the code behaves, except for the one detail flagged inline.
Top priorities: (1) the docs table row for transformHtml. Nothing else needs to change before merge.
claude-opus-5-5 | 𝕏
The Error Handling table said a failing onLoad or transformHtml only leaves that page unwritten. The onLoad prepass stops the build before any page is written; only the docs index, compiled outside the prepass, leaves just that page out. transformHtml on the landing or 404 page is not caught per page, so the build stops there and skips the later pages, the search index, the build cache and onEnd. transformFrontmatter now says it concerns docs pages. Checked with a probe plugin on Bun and Node.
There was a problem hiding this comment.
✅ No new issues found. The docs table now matches what the build does.
Reviewed changes
Reviewed in senior mode, covering only commit 08245fe. The only change is to the "Error Handling" table in plugins.mdx. I checked each rewritten row against build.ts. Verdict: READY.
- Updated the
onLoadrow: the row now says a prepass failure stops the build before any page is written. The docs index is the exception: itsonLoadcall is inside atry/catch(build.ts:447-463), so only that page is left out and the build exits 1. - Updated the
transformHtmlrow: on a docs page, only that page is left out. On the landing page or the 404 page (build.ts:679/:729, outside anytry/catch), the build stops, so the remaining pages,runOnEnd,generateSearchIndexandwriteCache(build.ts:761-775) are skipped. - Updated the
transformFrontmatterrow: the row now says this applies to docs pages, which matches the per-pageerrorspath.
claude-opus-5-5 | 𝕏

Summary
Last follow-up from the plugin security audit (after #482 and #484).
flame buildnow fails when a plugin hook throws, instead of logging the error and exiting with code 0.flame devkeeps logging and serving.Cause
onStart,onLoad,transformFrontmatter,transformHtmlandonEndcaught every error, logged it, and carried on. The build still exited 0 and shipped pages without that hook's work. For example, anonLoadplugin that removes internal content published the unchanged source when it threw, and CI saw a green build.Fix
BuildPluginBuildertakes{ strict }(BuildPluginBuilderOptions, defaultfalse). In strict mode each execution hook rethrows the first error as[plugin] <hook> error: <message>, with the original error ascause.[plugin] transformHtml callback #1 on docs/getting-started/overview.mdx error: …. The lenient log lines gain the same detail.handleRequestalways logs, since it only runs inflame dev.flame buildsetsstrict: true, in bothbuild.ts(Bun) andbuild.impl.ts(Node/Deno). The existing build error paths then do the rest:flame buildflame devonStartonLoadtransformFrontmatter/transformHtmltransformHtmlon the landing or 404 pageonEndare skippedonEndhandleRequestflame dev(server.ts,server.impl.ts) keeps the lenient default, so one broken plugin does not stop the server while it is being fixed.Docs.
flame buildand aflame devcolumn and an example error line.onStartand lifecycle text, and the hook JSDoc inplugin.tsandplugin-builder.ts, now describe the build-versus-dev behaviour.Changeset:
@docubook/flameminor, since this changes behaviour. The changeset group islinked, so the release will be 2.6.0. The changeset tells authors who threw on purpose to report a soft problem to log a warning instead.Not changed
transformHtml, or a non-object fromtransformFrontmatter. This PR only covers thrown errors.Verification
Temp project, end to end. The template with a probe plugin that throws from one hook, chosen by an env var. Each run used a clean
.docu.onStartonLoad(overview.mdx)transformHtml(overview)onEndAdded after review (08245fe):
onLoadthrowing ondocs/index.mdxgives exit 1 and leaves only the docs index unwritten.transformHtmlthrowing on the landing page gives exit 1, writes all docs pages, and skips the landing page, the 404 page, the search index andonEnd. Bun and Node behave the same.flame devon both runtimes, withonStart,onLoad,transformHtmlorhandleRequestthrowing:/docsand/docs/getting-started/overviewreturn 200, and the error is logged with its hook and file.Checks.
oxlint, andtsc --noEmitpass.onStartrejects and stops later callbacks;onLoadrejects with the path andcauseinstead of trying the next handler;transformFrontmatterandtransformHtmlname the file;onEndrejects;handleRequeststill isolates errors;nullpage context, which now passespageCtx().scripts/check-release-plan.mjs(6 scenarios) pass.