Skip to content

feat(flame): fail the build when a plugin hook throws - #485

Merged
gitfromwildan merged 2 commits into
mainfrom
feat/strict-plugin-hooks
Nov 6, 2026
Merged

gitfromwildan merged 2 commits into
mainfrom
feat/strict-plugin-hooks

Conversation

@gitfromwildan

@gitfromwildan gitfromwildan commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Last follow-up from the plugin security audit (after #482 and #484). flame build now fails when a plugin hook throws, instead of logging the error and exiting with code 0. flame dev keeps logging and serving.

Cause

onStart, onLoad, transformFrontmatter, transformHtml and onEnd caught every error, logged it, and carried on. The build still exited 0 and shipped pages without that hook's work. For example, an onLoad plugin that removes internal content published the unchanged source when it threw, and CI saw a green build.

Fix

  • BuildPluginBuilder takes { strict } (BuildPluginBuilderOptions, default false). In strict mode each execution hook rethrows the first error as [plugin] <hook> error: <message>, with the original error as cause.

    • Page hooks name the source file, e.g. [plugin] transformHtml callback #1 on docs/getting-started/overview.mdx error: …. The lenient log lines gain the same detail.
    • handleRequest always logs, since it only runs in flame dev.
  • flame build sets strict: true, in both build.ts (Bun) and build.impl.ts (Node/Deno). The existing build error paths then do the rest:

    Hook flame build flame dev
    onStart fails before any page is written log + continue
    onLoad fails before any page is written; for the docs index, only that page is not written log + try next handler
    transformFrontmatter / transformHtml on a docs page, that page is not written and the others are, exit code 1 log + value unchanged
    transformHtml on the landing or 404 page the build stops; later pages, search index, build cache and onEnd are skipped log + HTML unchanged
    onEnd fails after the pages are written; search index and build cache are not not run
    handleRequest not run log + continue
  • flame 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.

    • The plugin guide's "Error Isolation" section becomes "Error Handling", with a flame build and a flame dev column and an example error line.
    • The Step 5, onStart and lifecycle text, and the hook JSDoc in plugin.ts and plugin-builder.ts, now describe the build-versus-dev behaviour.
  • Changeset: @docubook/flame minor, since this changes behaviour. The changeset group is linked, 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

  • A hook that returns an invalid value still warns and is skipped in both modes: a non-string from transformHtml, or a non-object from transformFrontmatter. 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.

    Hook throwing Bun build Node build
    none exit 0, 6 pages exit 0, 6 pages
    onStart exit 1, 0 pages exit 1, 0 pages
    onLoad (overview.mdx) exit 1, 0 pages exit 1, 0 pages
    transformHtml (overview) exit 1, 5 pages, overview missing exit 1, 5 pages, overview missing
    onEnd exit 1, 6 pages exit 1, 6 pages

    Added after review (08245fe): onLoad throwing on docs/index.mdx gives exit 1 and leaves only the docs index unwritten. transformHtml throwing on the landing page gives exit 1, writes all docs pages, and skips the landing page, the 404 page, the search index and onEnd. Bun and Node behave the same.

    flame dev on both runtimes, with onStart, onLoad, transformHtml or handleRequest throwing: /docs and /docs/getting-started/overview return 200, and the error is logged with its hook and file.

  • Checks.

    • flame: 860 tests in 42 files, oxlint, and tsc --noEmit pass.
    • New strict-mode tests:
      • onStart rejects and stops later callbacks;
      • onLoad rejects with the path and cause instead of trying the next handler;
      • transformFrontmatter and transformHtml name the file;
      • onEnd rejects;
      • handleRequest still isolates errors;
      • successful hooks behave as in lenient mode.
    • The lenient tests are unchanged, except one that passed a null page context, which now passes pageCtx().
    • The pre-push hooks (commitlint, lint, build) and scripts/check-release-plan.mjs (6 scenarios) pass.

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.
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Preview Nov 6, 2026 5:47am UTC

@gitfromwildan gitfromwildan self-assigned this Nov 6, 2026

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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 new hookFailed() helper keeps the five catch blocks DRY. In strict mode it rethrows [plugin] <hook> error: … with the original error as cause.
  • Strict in flame build only: both build entrypoints pass { strict: true }. server.ts and server.impl.ts keep the default. deploy.ts checks the child's exit code and deploy.shared.ts goes through runBuildCli(), so a failing hook also stops flame deploy.
  • Error propagation: a failing docs page hook is caught for that page and counted in errors, which gives exit 1. A prepass onLoad error aborts the build through Promise.all. onStart and onEnd errors reach the top-level Build failed handler. Because the build re-renders every page when plugins are configured (the !builder guards), skipping writeCache() cannot hide a failure on the next run.
  • Docs and changeset: the new "Error Handling" table, the JSDoc updates and the minor changeset 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 onLoad row: the row now says a prepass failure stops the build before any page is written. The docs index is the exception: its onLoad call is inside a try/catch (build.ts:447-463), so only that page is left out and the build exits 1.
  • Updated the transformHtml row: on a docs page, only that page is left out. On the landing page or the 404 page (build.ts:679 / :729, outside any try/catch), the build stops, so the remaining pages, runOnEnd, generateSearchIndex and writeCache (build.ts:761-775) are skipped.
  • Updated the transformFrontmatter row: the row now says this applies to docs pages, which matches the per-page errors path.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@gitfromwildan
gitfromwildan merged commit a3f1f1b into main Nov 6, 2026
14 of 15 checks passed
@gitfromwildan
gitfromwildan deleted the feat/strict-plugin-hooks branch November 6, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant