Unverified Commit 1a9b0f6f authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

improve internal error logging (#55582)

### What?

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


Closes WEB-1605
parent 06315491
......@@ -3,12 +3,11 @@ 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) =>
......@@ -16,8 +15,12 @@ export function logAppDirError(err: any) {
!/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)}`)
}
......
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