From 1a9b0f6f7a03ccdc825f92c654b8ca991f27d3fc Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Tue, 19 Sep 2023 15:46:26 +0200 Subject: [PATCH] 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 --- .../next/src/server/dev/log-app-dir-error.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/next/src/server/dev/log-app-dir-error.ts b/packages/next/src/server/dev/log-app-dir-error.ts index 7247b192f4c0d..a4c0a3314b641 100644 --- a/packages/next/src/server/dev/log-app-dir-error.ts +++ b/packages/next/src/server/dev/log-app-dir-error.ts @@ -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)}`) }