-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
handle uncaught exceptions in worker
Previously any uncaught exception in a build worker would lead to the worker process being exited. This change adds a custom handler to only terminate the process if the error is a Next.js specific API that expects to be called in a context where the framework can observe it. Other errors that are uncaught are logged but won't terminate the worker process.
- Loading branch information
Showing
5 changed files
with
184 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { isDynamicServerError } from '../../client/components/hooks-server-context' | ||
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' | ||
import { isNextRouterError } from '../../client/components/is-next-router-error' | ||
import { isDynamicPostpone } from '../../server/app-render/dynamic-rendering' | ||
|
||
export const isDynamicUsageError = (err: unknown) => | ||
isDynamicServerError(err) || | ||
isBailoutToCSRError(err) || | ||
isNextRouterError(err) | ||
isNextRouterError(err) || | ||
isDynamicPostpone(err) |
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
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
20 changes: 20 additions & 0 deletions
20
test/production/app-dir/build-output/app/uncaught-error/page.tsx
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,20 @@ | ||
import { PHASE_PRODUCTION_BUILD } from 'next/constants' | ||
|
||
export default function Page() { | ||
setTimeout(() => { | ||
throw new Error('Boom') | ||
}, 0) | ||
return ( | ||
<> | ||
<p> | ||
This page should be statically generated even though we threw an | ||
unhandled exception in a setTimeout. | ||
</p> | ||
<p id="sentinel"> | ||
{process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD | ||
? 'at buildtime' | ||
: 'at runtime'} | ||
</p> | ||
</> | ||
) | ||
} |
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