Error handling bugfix: pass #1
This commit is contained in:
Vendored
+6
@@ -22,6 +22,12 @@ export default function () {
|
||||
global.BUNEXT_SKIPPED_BROWSER_MODULES = new Set();
|
||||
await bunextInit({ build_only: true });
|
||||
// await pagesSSRBundler();
|
||||
// A failed bundle must fail the command: CI and scripts rely on
|
||||
// the exit code instead of grepping logs.
|
||||
if (global.BUNEXT_BUILD_FAILED) {
|
||||
log.error("Build failed with errors. Exiting.");
|
||||
process.exit(1);
|
||||
}
|
||||
if (global.BUNEXT_BUNDLER_CTX_MAP) {
|
||||
let bundler_ctx_json_str = JSON.stringify(global.BUNEXT_BUNDLER_CTX_MAP);
|
||||
writeFileSync(BUNDLER_CTX_MAP_JSON, bundler_ctx_json_str, "utf-8");
|
||||
|
||||
Vendored
+14
@@ -2,13 +2,23 @@ import startServer from "../../functions/server/start-server";
|
||||
import { log } from "../../utils/log";
|
||||
import bunextInit from "../../functions/bunext-init";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import writeErrorFile from "../../functions/write-error-file";
|
||||
import { rmSync } from "fs";
|
||||
const { HYDRATION_DST_DIR, BUNX_CWD_PAGES_REWRITE_DIR } = grabDirNames();
|
||||
// The supervisor only restarts the dev server when this process actually
|
||||
// exits with a code. Registering a listener that merely logs (the previous
|
||||
// behavior) keeps Bun from exiting: the crash is swallowed, no error file is
|
||||
// written, and the supervisor never restarts the server. Log, record the real
|
||||
// error, and exit non-zero so recovery actually runs.
|
||||
process.on("uncaughtException", (error) => {
|
||||
log.error(`Uncaught exception: ${error}`);
|
||||
writeErrorFile({ error, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
});
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
log.error(`Unhandled rejection: ${reason}`);
|
||||
writeErrorFile({ error: reason, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
});
|
||||
log.info("Running development server ...");
|
||||
try {
|
||||
@@ -21,5 +31,9 @@ try {
|
||||
await startServer();
|
||||
}
|
||||
catch (error) {
|
||||
// Startup failures (e.g. port in use, config errors) must exit non-zero;
|
||||
// otherwise the process hangs alive with no server and no restart.
|
||||
log.error(`Failed to start development server: ${error}`);
|
||||
writeErrorFile({ error, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Vendored
+9
-2
@@ -3,7 +3,7 @@ import path from "path";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import writeErrorFile from "../../functions/write-error-file";
|
||||
import { existsSync, rmSync } from "fs";
|
||||
const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON } = grabDirNames();
|
||||
const { BUNDLER_CTX_MAP_JSON, SSR_BUNDLER_CTX_MAP_JSON, BUNX_BUNDLER_ERROR_EXIT_FILE, } = grabDirNames();
|
||||
let retries = 0;
|
||||
let timeout;
|
||||
const MAX_RETRIES = 5;
|
||||
@@ -14,6 +14,10 @@ export default function () {
|
||||
try {
|
||||
rmSync(SSR_BUNDLER_CTX_MAP_JSON, { recursive: true });
|
||||
rmSync(BUNDLER_CTX_MAP_JSON, { recursive: true });
|
||||
// A stale error file from a previous session makes the bundler
|
||||
// run in "silent" mode and pages fail with misleading
|
||||
// "Application Error" messages until the first rebuild.
|
||||
rmSync(BUNX_BUNDLER_ERROR_EXIT_FILE, { force: true });
|
||||
}
|
||||
catch (error) { }
|
||||
await dev();
|
||||
@@ -54,7 +58,10 @@ async function dev() {
|
||||
return await dev();
|
||||
}
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
// Restart on any numeric exit (0 included: the server should never exit
|
||||
// cleanly). A null exit means the child was killed by a signal (e.g.
|
||||
// Ctrl+C in the shared terminal), which we must not restart.
|
||||
if (exited != null) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
|
||||
Vendored
+9
-2
@@ -1,7 +1,9 @@
|
||||
import { Command } from "commander";
|
||||
import path from "path";
|
||||
import writeErrorFile from "../../functions/write-error-file";
|
||||
import { existsSync } from "fs";
|
||||
import grabDirNames from "../../utils/grab-dir-names";
|
||||
import { existsSync, rmSync } from "fs";
|
||||
const { BUNX_BUNDLER_ERROR_EXIT_FILE } = grabDirNames();
|
||||
let retries = 0;
|
||||
let timeout;
|
||||
const MAX_RETRIES = 5;
|
||||
@@ -9,6 +11,9 @@ export default function () {
|
||||
return new Command("start")
|
||||
.description("Start production server")
|
||||
.action(async () => {
|
||||
// A stale error file from a previous session makes the bundler
|
||||
// run in "silent" mode and pages fail with misleading messages.
|
||||
rmSync(BUNX_BUNDLER_ERROR_EXIT_FILE, { force: true });
|
||||
await start();
|
||||
});
|
||||
}
|
||||
@@ -47,7 +52,9 @@ async function start() {
|
||||
return await start();
|
||||
}
|
||||
const exited = await dev_process.exited;
|
||||
if (exited) {
|
||||
// Restart on any numeric exit (0 included). A null exit means the child
|
||||
// was killed by a signal, which we must not restart.
|
||||
if (exited != null) {
|
||||
retries++;
|
||||
timeout = setTimeout(() => {
|
||||
retries = 0;
|
||||
|
||||
Vendored
+23
-2
@@ -1,6 +1,27 @@
|
||||
import bunextInit from "../../functions/bunext-init";
|
||||
import startServer from "../../functions/server/start-server";
|
||||
import { log } from "../../utils/log";
|
||||
import writeErrorFile from "../../functions/write-error-file";
|
||||
// Same crash contract as the dev child: log the real error, record it in the
|
||||
// error file, and exit non-zero so the supervisor can restart and so the
|
||||
// bundler pipeline sees the failure.
|
||||
process.on("uncaughtException", (error) => {
|
||||
log.error(`Uncaught exception: ${error}`);
|
||||
writeErrorFile({ error, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
});
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
log.error(`Unhandled rejection: ${reason}`);
|
||||
writeErrorFile({ error: reason, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
});
|
||||
log.info("Starting production server ...");
|
||||
await bunextInit();
|
||||
await startServer();
|
||||
try {
|
||||
await bunextInit();
|
||||
await startServer();
|
||||
}
|
||||
catch (error) {
|
||||
log.error(`Failed to start production server: ${error}`);
|
||||
writeErrorFile({ error, exitCode: 1, force: true });
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user