Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide stack trace in CanaryOnlyError #72859

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions packages/next/src/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,29 @@ describe('loadConfig', () => {
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 () => {
await expect(
loadConfig('', __dirname, {
Expand Down
3 changes: 3 additions & 0 deletions packages/next/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1283,5 +1283,8 @@ class CanaryOnlyError extends Error {
super(
`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
}
}
Loading