Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions packages/angular/build/src/utils/server-rendering/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,12 @@ export async function prerenderPages(
sourcemap,
outputMode,
).catch((err) => {
assertIsError(err);

return {
errors: [`An error occurred while extracting routes.\n\n${err.message ?? err.stack ?? err}`],
errors: [
`An error occurred while extracting routes.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the logical OR operator (||) here instead of nullish coalescing (??). While ?? handles null and undefined, it doesn't handle empty strings. Properties like err.stack or err.message can be empty strings, which would cause this expression to resolve to an empty string, hiding error details. Using || would be more robust as it treats empty strings as falsy and falls back to the next property, ensuring a more descriptive error is always displayed.

Suggested change
`An error occurred while extracting routes.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
`An error occurred while extracting routes.\n\n${err.stack || err.message || err.code || err}`

],
serializedRouteTree: [],
appShellRoute: undefined,
};
Expand Down Expand Up @@ -265,8 +269,9 @@ async function renderPages(
}
})
.catch((err) => {
assertIsError(err);
errors.push(
`An error occurred while prerendering route '${route}'.\n\n${err.message ?? err.stack ?? err.code ?? err}`,
`An error occurred while prerendering route '${route}'.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the logical OR operator (||) here instead of nullish coalescing (??). While ?? handles null and undefined, it doesn't handle empty strings. Properties like err.stack or err.message can be empty strings, which would cause this expression to resolve to an empty string, hiding error details. Using || would be more robust as it treats empty strings as falsy and falls back to the next property, ensuring a more descriptive error is always displayed.

Suggested change
`An error occurred while prerendering route '${route}'.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
`An error occurred while prerendering route '${route}'.\n\n${err.stack || err.message || err.code || err}`

);
void renderWorker.destroy();
});
Expand Down Expand Up @@ -371,7 +376,7 @@ async function getAllRoutes(

return {
errors: [
`An error occurred while extracting routes.\n\n${err.message ?? err.stack ?? err.code ?? err}`,
`An error occurred while extracting routes.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider using the logical OR operator (||) here instead of nullish coalescing (??). While ?? handles null and undefined, it doesn't handle empty strings. Properties like err.stack or err.message can be empty strings, which would cause this expression to resolve to an empty string, hiding error details. Using || would be more robust as it treats empty strings as falsy and falls back to the next property, ensuring a more descriptive error is always displayed.

Suggested change
`An error occurred while extracting routes.\n\n${err.stack ?? err.message ?? err.code ?? err}`,
`An error occurred while extracting routes.\n\n${err.stack || err.message || err.code || err}`

],
serializedRouteTree: [],
};
Expand Down
Loading