Unverified Commit b5f5495b authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

hide stack trace in CanaryOnlyError (#72859)

This error doesn't point to any particularly meaningful line of code to
the user, we just use it to have a well-known error message for when a
feature should only be used in canary. This hides the stack trace so the
error is surfaced more clearly.
parent a72d79c3
...@@ -71,6 +71,29 @@ describe('loadConfig', () => { ...@@ -71,6 +71,29 @@ describe('loadConfig', () => {
delete process.env.__NEXT_VERSION delete process.env.__NEXT_VERSION
}) })
it('should not print a stack trace when throwing an error', async () => {
const loadConfigPromise = loadConfig('', __dirname, {
customConfig: {
experimental: {
ppr: true,
},
},
})
await expect(loadConfigPromise).rejects.toThrow(
/The experimental feature "experimental.ppr" can only be enabled when using the latest canary version of Next.js./
)
try {
await loadConfigPromise
} catch (error: any) {
expect(error).toBeInstanceOf(Error)
// Check that there's no stack trace
expect(error.stack).toBeUndefined()
}
})
it('errors when using PPR if not in canary', async () => { it('errors when using PPR if not in canary', async () => {
await expect( await expect(
loadConfig('', __dirname, { loadConfig('', __dirname, {
......
...@@ -1283,5 +1283,8 @@ class CanaryOnlyError extends Error { ...@@ -1283,5 +1283,8 @@ class CanaryOnlyError extends Error {
super( super(
`The experimental feature "${feature}" can only be enabled when using the latest canary version of Next.js.` `The experimental feature "${feature}" can only be enabled when using the latest canary version of Next.js.`
) )
// This error is meant to interrupt the server start/build process
// but the stack trace isn't meaningful, as it points to internal code.
this.stack = undefined
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment