Error handling bugfix: pass #1

This commit is contained in:
2026-10-02 07:04:22 +01:00
parent 39a5e91eeb
commit d8ea4f8e02
53 changed files with 1179 additions and 410 deletions
+21 -8
View File
@@ -10,6 +10,7 @@ import isDevelopment from "../../../utils/is-development";
import { existsSync } from "fs";
import grabDirNames from "../../../utils/grab-dir-names";
import grabRelativePath from "../../../utils/grab-relative-path";
import { logBuildErrorsOnce } from "../../../utils/build-error-log";
const { BUNX_BUNDLER_ERROR_EXIT_FILE, ROOT_DIR } = grabDirNames();
class NotFoundError extends Error {
status = 404;
@@ -19,7 +20,7 @@ class NotFoundError extends Error {
}
}
export default async function grabPageComponent(params) {
const { req, file_path: passed_file_path, debug, return_server_res_only, skip_server_res, is_hydration, } = params;
const { req, file_path: passed_file_path, debug, return_server_res_only, skip_server_res, is_hydration, no_retry, } = params;
const url = req?.url ? new URL(req.url) : undefined;
const router = global.BUNEXT_ROUTER;
const is_dev = isDevelopment();
@@ -59,14 +60,20 @@ export default async function grabPageComponent(params) {
}
let retries = 0;
const MAX_RETRIES = 2;
while (retries < MAX_RETRIES) {
// Only retry transient failures: if the last rebuild failed
// (BUNEXT_BUILD_FAILED), the file is broken and more rebuilds
// will just repeat the same error.
while (retries < MAX_RETRIES &&
!global.BUNEXT_BUILD_FAILED) {
await fullRebuild({
msg: `Retrying Bundle map for file \`${relative_file_path}\``,
});
await Bun.sleep(1000);
bundledMap = global.BUNEXT_BUNDLER_CTX_MAP[relative_file_path];
bundledMap =
global.BUNEXT_BUNDLER_CTX_MAP[relative_file_path];
if (bundledMap?.path)
break;
retries++;
}
if (!bundledMap?.path) {
const errMsg = `No Bundled File Path for this request path!`;
@@ -116,8 +123,11 @@ export default async function grabPageComponent(params) {
const is404 = error instanceof NotFoundError ||
error?.name === "NotFoundError" ||
error?.status === 404;
if (!params.retry && is_dev) {
while (global.BUNEXT_REBUILD_RETRIES < 2) {
if (!params.retry && !params.no_retry && is_dev) {
// Skip the retry cascade when the last rebuild failed: the error
// is persistent and more rebuilds would repeat it endlessly.
while (!global.BUNEXT_BUILD_FAILED &&
global.BUNEXT_REBUILD_RETRIES < 2) {
global.BUNEXT_REBUILD_RETRIES =
global.BUNEXT_REBUILD_RETRIES + 1;
await fullRebuild();
@@ -139,9 +149,12 @@ export default async function grabPageComponent(params) {
global.BUNEXT_IS_404_PAGE = true;
}
else {
log.error(`Error Grabbing Page Component: ${error.message}`);
log.error(`Page: ${passed_file_path || url?.pathname}`);
if (is_dev) {
logBuildErrorsOnce([
{
text: `Error Grabbing Page Component: ${error.message}; Page: ${passed_file_path || url?.pathname}`,
},
], (line) => log.error(line));
if (is_dev && !params.no_retry && !global.BUNEXT_BUILD_FAILED) {
fullRebuild();
}
}