Skip to content

Commit 691019e

Browse files
committed
fix(@angular/build): improve error message when an unhandled exception occurs during prerendering
This change enhances the error messaging when an unhandled exception occurs during the prerendering process. The updated error message provides more context and clarity. **Previous Behavior** ``` ng b An unhandled exception occurred: Some error!!! See "/tmp/ng-S2ABKF/angular-errors.log" for further details. ``` **Updated Behavior:** ``` ng b Browser bundles Initial chunk files | Names | Raw size | Estimated transfer size main-AFPIPGGK.js | main | 218.00 kB | 59.48 kB polyfills-Z2GOM3BN.js | polyfills | 35.82 kB | 11.80 kB styles-5INURTSO.css | styles | 0 bytes | 0 bytes | Initial total | 253.82 kB | 71.28 kB Server bundles Initial chunk files | Names | Raw size server.mjs | server | 1.11 MB | chunk-HZL5H5M5.mjs | - | 526.77 kB | polyfills.server.mjs | polyfills.server | 269.91 kB | chunk-GFWAPST7.mjs | - | 19.16 kB | chunk-5XUXGTUW.mjs | - | 2.55 kB | render-utils.server.mjs | render-utils.server | 1.46 kB | main.server.mjs | main.server | 149 bytes | Lazy chunk files | Names | Raw size chunk-7YC4RJ5P.mjs | xhr2 | 12.08 kB | Prerendered 1 static route. Application bundle generation failed. [4.923 seconds] ✘ [ERROR] An error occurred while prerendering route '/'. Error: Some error!!! at render (node_modules/@angular/build/src/utils/server-rendering/render-worker.js:20:20) at /angular-cli/abc/node_modules/piscina/dist/worker.js:146:32 ``` Closes #28212
1 parent a7f466a commit 691019e

File tree

1 file changed

+37
-20
lines changed
  • packages/angular/build/src/utils/server-rendering

1 file changed

+37
-20
lines changed

packages/angular/build/src/utils/server-rendering/prerender.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ export async function prerenderPages(
8181
}
8282

8383
// Get routes to prerender
84-
const { routes: allRoutes, warnings: routesWarnings } = await getAllRoutes(
84+
const {
85+
routes: allRoutes,
86+
warnings: routesWarnings,
87+
errors: routesErrors,
88+
} = await getAllRoutes(
8589
workspaceRoot,
8690
outputFilesForWorker,
8791
assetsReversed,
@@ -92,11 +96,15 @@ export async function prerenderPages(
9296
verbose,
9397
);
9498

99+
if (routesErrors?.length) {
100+
errors.push(...routesErrors);
101+
}
102+
95103
if (routesWarnings?.length) {
96104
warnings.push(...routesWarnings);
97105
}
98106

99-
if (allRoutes.size < 1) {
107+
if (allRoutes.size < 1 || errors.length > 0) {
100108
return {
101109
errors,
102110
warnings,
@@ -190,22 +198,27 @@ async function renderPages(
190198
const isAppShellRoute = appShellRoute === route;
191199
const serverContext: ServerContext = isAppShellRoute ? 'app-shell' : 'ssg';
192200
const render: Promise<RenderResult> = renderWorker.run({ route, serverContext });
193-
const renderResult: Promise<void> = render.then(({ content, warnings, errors }) => {
194-
if (content !== undefined) {
195-
const outPath = isAppShellRoute
196-
? 'index.html'
197-
: posix.join(removeLeadingSlash(route), 'index.html');
198-
output[outPath] = content;
199-
}
200-
201-
if (warnings) {
202-
warnings.push(...warnings);
203-
}
204-
205-
if (errors) {
206-
errors.push(...errors);
207-
}
208-
});
201+
const renderResult: Promise<void> = render
202+
.then(({ content, warnings, errors }) => {
203+
if (content !== undefined) {
204+
const outPath = isAppShellRoute
205+
? 'index.html'
206+
: posix.join(removeLeadingSlash(route), 'index.html');
207+
output[outPath] = content;
208+
}
209+
210+
if (warnings) {
211+
warnings.push(...warnings);
212+
}
213+
214+
if (errors) {
215+
errors.push(...errors);
216+
}
217+
})
218+
.catch((err) => {
219+
errors.push(`An error occurred while prerendering route '${route}'.\n\n${err.stack}`);
220+
void renderWorker.destroy();
221+
});
209222

210223
renderingPromises.push(renderResult);
211224
}
@@ -231,7 +244,7 @@ async function getAllRoutes(
231244
prerenderOptions: PrerenderOptions,
232245
sourcemap: boolean,
233246
verbose: boolean,
234-
): Promise<{ routes: Set<string>; warnings?: string[] }> {
247+
): Promise<{ routes: Set<string>; warnings?: string[]; errors?: string[] }> {
235248
const { routesFile, discoverRoutes } = prerenderOptions;
236249
const routes = new RoutesSet();
237250
const { route: appShellRoute } = appShellOptions;
@@ -275,8 +288,12 @@ async function getAllRoutes(
275288
recordTiming: false,
276289
});
277290

291+
const errors: string[] = [];
278292
const { routes: extractedRoutes, warnings }: RoutersExtractorWorkerResult = await renderWorker
279293
.run({})
294+
.catch((err) => {
295+
errors.push(`An error occurred while extracting routes.\n\n${err.stack}`);
296+
})
280297
.finally(() => {
281298
void renderWorker.destroy();
282299
});
@@ -285,7 +302,7 @@ async function getAllRoutes(
285302
routes.add(route);
286303
}
287304

288-
return { routes, warnings };
305+
return { routes, warnings, errors };
289306
}
290307

291308
function addLeadingSlash(value: string): string {

0 commit comments

Comments
 (0)