forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dynamicIO] warn in debug mode when prospective renders error (vercel…
…#71266) When prerendering pages and routes errors with dynamicIO enabled, errors during the prospective render may be supressed from logging. Normally this is expected and ok because the dynamic portion of a render may be expected to error during prerendering. However some codepaths are not hit the same between the prospective and final renders and so it can be useful to have the ability to get additional insight into the runtime behavior of the prospective render. This change adds extra logging when `process.env.NEXT_DEBUG_BUILD` is enabled. When this environment variable is set we log errors that throw during the prospective render.
- Loading branch information
Showing
15 changed files
with
578 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/next/src/server/app-render/prospective-render-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export function printDebugThrownValueForProspectiveRender( | ||
thrownValue: unknown, | ||
route: string | ||
) { | ||
let message: undefined | string | ||
if ( | ||
typeof thrownValue === 'object' && | ||
thrownValue !== null && | ||
typeof (thrownValue as any).message === 'string' | ||
) { | ||
message = (thrownValue as any).message | ||
if (typeof (thrownValue as any).stack === 'string') { | ||
const originalErrorStack: string = (thrownValue as any).stack | ||
const stackStart = originalErrorStack.indexOf('\n') | ||
if (stackStart > -1) { | ||
const error = new Error( | ||
`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. | ||
Original Error: ${message}` | ||
) | ||
error.stack = | ||
'Error: ' + error.message + originalErrorStack.slice(stackStart) | ||
console.error(error) | ||
return | ||
} | ||
} | ||
} else if (typeof thrownValue === 'string') { | ||
message = thrownValue | ||
} | ||
|
||
if (message) { | ||
console.error(`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. No stack was provided. | ||
Original Message: ${message}`) | ||
return | ||
} | ||
|
||
console.error( | ||
`Route ${route} errored during the prospective render. These errors are normally ignored and may not prevent the route from prerendering but are logged here because build debugging is enabled. The thrown value is logged just following this message` | ||
) | ||
console.error(thrownValue) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.