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

improve internal error logging #55582

Merged
merged 1 commit into from
Sep 19, 2023
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
19 changes: 11 additions & 8 deletions packages/next/src/server/dev/log-app-dir-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import * as Log from '../../build/output/log'

export function logAppDirError(err: any) {
if (isError(err) && err?.stack) {
const filteredStack = err.stack
.split('\n')
.map((line: string) =>
// Remove 'webpack-internal:' noise from the path
line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '')
)
const cleanedStack = err.stack.split('\n').map((line: string) =>
// Remove 'webpack-internal:' noise from the path
line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '')
)
const filteredStack = cleanedStack
// Only display stack frames from the user's code
.filter(
(line: string) =>
!/next[\\/]dist[\\/]compiled/.test(line) &&
!/node_modules[\\/]/.test(line) &&
!/node:internal[\\/]/.test(line)
)
.join('\n')
Log.error(filteredStack)
if (filteredStack.length === 1) {
// This is an error that happened outside of user code, keep full stack
Log.error(`Internal error: ${cleanedStack.join('\n')}`)
} else {
Log.error(filteredStack.join('\n'))
}
if (typeof (err as any).digest !== 'undefined') {
console.error(`digest: ${JSON.stringify((err as any).digest)}`)
}
Expand Down