Skip to content

Commit

Permalink
fix: Add route information to render errors (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Jahred Hope <[email protected]>
  • Loading branch information
mrm007 and jahredhope authored Feb 8, 2023
1 parent bf2cf08 commit 6d822a0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ export default class HtmlRenderPlugin<Route extends BaseRoute = BaseRoute> {
`Successfully rendered ${route.route} (${timeSince(startRenderTime)})`
);
return result;
} catch (error) {
error.webpackStats = webpackStats;
} catch (error: any) {
log(`Error rendering ${route.route}`);
if (error) {
error.route = route.route;
error.webpackStats = webpackStats;
}
throw error;
}
};
Expand Down
7 changes: 5 additions & 2 deletions src/renderRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TransformPath,
Render,
FileSystem,
BaseRoute,
} from "./common-types";
import { Compilation } from "webpack";
import { log } from "./logging";
Expand Down Expand Up @@ -53,7 +54,7 @@ function safeMkdir(fileSystem: FileSystem, dir: string) {
});
}

export default async function renderRoutes<Route>({
export default async function renderRoutes<Route extends BaseRoute>({
render: performRender,
renderConcurrency,
routes,
Expand Down Expand Up @@ -98,7 +99,9 @@ export default async function renderRoutes<Route>({
renderResult = await performRender(route);
} catch (error) {
console.error(
`🚨 ${chalk.red(`An error occurred rendering "`)}". Exiting render.`
`🚨 ${chalk.red(
`An error occurred rendering route: "${route.route}"`
)}. Exiting render.`
);
throw error;
}
Expand Down
5 changes: 4 additions & 1 deletion tests/test-cases/render-when-ready/render-when-ready.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ describe("renderWhenReady", () => {

compiler.run(async () => {
await expect(promise).rejects.toEqual(
expect.objectContaining({ webpackStats: expect.any(Object) })
expect.objectContaining({
route: "/new",
webpackStats: expect.any(Object),
})
);
done();
});
Expand Down

0 comments on commit 6d822a0

Please sign in to comment.