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' ...@@ -3,12 +3,11 @@ import * as Log from '../../build/output/log'
export function logAppDirError(err: any) { export function logAppDirError(err: any) {
if (isError(err) && err?.stack) { if (isError(err) && err?.stack) {
const filteredStack = err.stack const cleanedStack = err.stack.split('\n').map((line: string) =>
.split('\n') // Remove 'webpack-internal:' noise from the path
.map((line: string) => line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '')
// Remove 'webpack-internal:' noise from the path )
line.replace(/(webpack-internal:\/\/\/|file:\/\/)(\(.*\)\/)?/, '') const filteredStack = cleanedStack
)
// Only display stack frames from the user's code // Only display stack frames from the user's code
.filter( .filter(
(line: string) => (line: string) =>
...@@ -16,8 +15,12 @@ export function logAppDirError(err: any) { ...@@ -16,8 +15,12 @@ export function logAppDirError(err: any) {
!/node_modules[\\/]/.test(line) && !/node_modules[\\/]/.test(line) &&
!/node:internal[\\/]/.test(line) !/node:internal[\\/]/.test(line)
) )
.join('\n') if (filteredStack.length === 1) {
Log.error(filteredStack) // 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') { if (typeof (err as any).digest !== 'undefined') {
console.error(`digest: ${JSON.stringify((err as any).digest)}`) 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