diff --git a/src/servers/plugins/generate.ts b/src/servers/plugins/generate.ts index 41ab4492..f9f72174 100644 --- a/src/servers/plugins/generate.ts +++ b/src/servers/plugins/generate.ts @@ -108,6 +108,20 @@ export type BuildResult = { ok: boolean; ms: number; outputs: number; error?: st * the owner to restart. Failure is returned rather than thrown: a plugin whose frontend will not compile * must leave the previous build in place and serving, not take the UI down with it. */ +/** + * Everything a failed build knows, as one string. + * + * `AggregateError` — which is what a bundler failure is — keeps its diagnostics in `errors` and puts a + * generic summary in `message`. Reading `.message` gives you "Bundle failed", which is true and useless. + */ +function describeBuildFailure(err: unknown): string { + if (err && typeof err === 'object' && 'errors' in err && Array.isArray((err as AggregateError).errors)) { + const parts = (err as AggregateError).errors.map((e) => String(e)); + if (parts.length) return parts.join('; ').slice(0, 1000); + } + return err instanceof Error ? err.message : String(err); +} + export async function rebuildFrontend(): Promise { const started = Date.now(); try { @@ -126,6 +140,20 @@ export async function rebuildFrontend(): Promise { const result = await Bun.build({ entrypoints: [HTML_ENTRY], outdir: STAGING_DIR, + /** + * WITHOUT THIS, EVERY BUILD FAILURE READS `Bundle failed` AND NOTHING ELSE. + * + * `Bun.build` THROWS on failure by default — an `AggregateError` whose own message is the string + * "Bundle failed" and whose `errors` array holds the real diagnostics. So the `result.success` + * branch below was unreachable, the catch reported the wrapper's summary, and the actual reason + * (`ModuleNotFound resolving "./Plugins.gen"`, a CSS `url()` that cannot be resolved, a syntax + * error with a file and a line) was thrown away at the moment it was most needed. + * + * Diagnosed by building a file that does not exist and printing the error's shape, after it cost + * twenty minutes of bisecting a themes refactor by hand. `throw: false` makes the returned result + * carry the logs, which is what the code below always assumed. + */ + throw: false, // WITHOUT THIS THE APP RENDERS UNSTYLED. // // `bunfig.toml` declares `[serve.static] plugins = ["bun-plugin-tailwind"]`, and that applies to @@ -141,10 +169,12 @@ export async function rebuildFrontend(): Promise { ok: false, ms: Date.now() - started, outputs: 0, + // 1000 rather than 500: a single bundler diagnostic with a file, a line and a code frame is + // routinely longer than 500 characters, and truncating mid-path leaves it unactionable. error: result.logs .map((l) => String(l)) .join('; ') - .slice(0, 500), + .slice(0, 1000), }; } // The shell must exist before anything is swapped in — a build reporting success without one is how