diff --git a/src/index.ts b/src/index.ts index a04fb78..a7a912d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -115,8 +115,12 @@ export default class HtmlRenderPlugin { `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; } }; diff --git a/src/renderRoutes.ts b/src/renderRoutes.ts index fce5f49..f0a7ff8 100644 --- a/src/renderRoutes.ts +++ b/src/renderRoutes.ts @@ -5,6 +5,7 @@ import { TransformPath, Render, FileSystem, + BaseRoute, } from "./common-types"; import { Compilation } from "webpack"; import { log } from "./logging"; @@ -53,7 +54,7 @@ function safeMkdir(fileSystem: FileSystem, dir: string) { }); } -export default async function renderRoutes({ +export default async function renderRoutes({ render: performRender, renderConcurrency, routes, @@ -98,7 +99,9 @@ export default async function renderRoutes({ 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; } diff --git a/tests/test-cases/render-when-ready/render-when-ready.test.ts b/tests/test-cases/render-when-ready/render-when-ready.test.ts index c18affb..121776a 100644 --- a/tests/test-cases/render-when-ready/render-when-ready.test.ts +++ b/tests/test-cases/render-when-ready/render-when-ready.test.ts @@ -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(); });