From c03f2a43f159fd7b49feb6bd9de20123bb7f614b Mon Sep 17 00:00:00 2001 From: Janka Uryga Date: Thu, 5 Dec 2024 18:14:03 +0100 Subject: [PATCH] nicer debug log --- .../server/after/stitch-after-callstack.ts | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/packages/next/src/server/after/stitch-after-callstack.ts b/packages/next/src/server/after/stitch-after-callstack.ts index 97ffc41518137d..e358f1d5fbc195 100644 --- a/packages/next/src/server/after/stitch-after-callstack.ts +++ b/packages/next/src/server/after/stitch-after-callstack.ts @@ -31,15 +31,37 @@ export function stitchAfterCallstack( replaceErrorStack(error, frames) } - console.log('AfterContext :: patchAfterCallstack', { - errorStack: origErrorStack, - nestedTaskCallerStacks: stackInfo.nestedTaskCallerStacks?.map( + console.log('='.repeat(60)) + console.log('AfterContext :: stitchAfterCallstack') + const indent = (depth: number, str: string) => + str + .split('\n') + .map((line) => ' '.repeat(depth) + line) + .join('\n') + const stackToStr = (str: string | null | undefined) => + indent(4, !str ? inspect(str) : str) + console.log(' errorStack:') + console.log(stackToStr(origErrorStack)) + console.log( + ' nestedTaskCallerStacks:', + ...(!stackInfo.nestedTaskCallerStacks + ? [stackInfo.nestedTaskCallerStacks] + : []) + ) + if (stackInfo.nestedTaskCallerStacks) { + for (const stack of stackInfo.nestedTaskCallerStacks?.map( (e) => e?.stack - ), - rootTaskCallerStack: stackInfo.rootTaskCallerStack?.stack, - rootTaskReactOwnerStack: stackInfo.rootTaskReactOwnerStack, - finalStack: frames ? error.stack : '', - }) + )) { + console.log(stackToStr(stack)) + } + } + console.log(' rootTaskCallerStack:') + console.log(stackToStr(stackInfo.rootTaskCallerStack?.stack)) + console.log(' rootTaskReactOwnerStack:') + console.log(stackToStr(stackInfo.rootTaskReactOwnerStack)) + console.log(' finalStack:') + console.log(stackToStr(frames ? error.stack : '')) + console.log('='.repeat(60)) return error }