Skip to content

Commit

Permalink
improve internal error logging (#55582)
Browse files Browse the repository at this point in the history
### What?

Makes sure that errors that have no user code in stack trace still show
an stack trace


Closes WEB-1605
  • Loading branch information
sokra committed Sep 19, 2023
1 parent 0631549 commit 1a9b0f6
Showing 1 changed file with 11 additions and 8 deletions.
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

0 comments on commit 1a9b0f6

Please sign in to comment.