Skip to content

Commit 6d822a0

Browse files
mrm007jahredhope
andauthored
fix: Add route information to render errors (#86)
Co-authored-by: Jahred Hope <[email protected]>
1 parent bf2cf08 commit 6d822a0

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ export default class HtmlRenderPlugin<Route extends BaseRoute = BaseRoute> {
115115
`Successfully rendered ${route.route} (${timeSince(startRenderTime)})`
116116
);
117117
return result;
118-
} catch (error) {
119-
error.webpackStats = webpackStats;
118+
} catch (error: any) {
119+
log(`Error rendering ${route.route}`);
120+
if (error) {
121+
error.route = route.route;
122+
error.webpackStats = webpackStats;
123+
}
120124
throw error;
121125
}
122126
};

src/renderRoutes.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
TransformPath,
66
Render,
77
FileSystem,
8+
BaseRoute,
89
} from "./common-types";
910
import { Compilation } from "webpack";
1011
import { log } from "./logging";
@@ -53,7 +54,7 @@ function safeMkdir(fileSystem: FileSystem, dir: string) {
5354
});
5455
}
5556

56-
export default async function renderRoutes<Route>({
57+
export default async function renderRoutes<Route extends BaseRoute>({
5758
render: performRender,
5859
renderConcurrency,
5960
routes,
@@ -98,7 +99,9 @@ export default async function renderRoutes<Route>({
9899
renderResult = await performRender(route);
99100
} catch (error) {
100101
console.error(
101-
`🚨 ${chalk.red(`An error occurred rendering "`)}". Exiting render.`
102+
`🚨 ${chalk.red(
103+
`An error occurred rendering route: "${route.route}"`
104+
)}. Exiting render.`
102105
);
103106
throw error;
104107
}

tests/test-cases/render-when-ready/render-when-ready.test.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ describe("renderWhenReady", () => {
5959

6060
compiler.run(async () => {
6161
await expect(promise).rejects.toEqual(
62-
expect.objectContaining({ webpackStats: expect.any(Object) })
62+
expect.objectContaining({
63+
route: "/new",
64+
webpackStats: expect.any(Object),
65+
})
6366
);
6467
done();
6568
});

0 commit comments

Comments
 (0)