Skip to content

Commit

Permalink
nicer debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Dec 6, 2024
1 parent a65072a commit 2313f46
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions packages/next/src/server/after/stitch-after-callstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
} from '../../client/components/react-dev-overlay/server/middleware-webpack'
import { replaceErrorStack } from '../../client/components/react-dev-overlay/internal/helpers/node-stack-frames'
import type { AfterTaskStore } from '../app-render/after-task-async-storage.external'
import { inspect } from 'node:util'

export const AFTER_CALLBACK_MARKER_FRAME = 'next-after-callback-marker-frame'
export const AFTER_PROMISE_MARKER_FRAME = 'next-after-promise-marker-frame'
Expand Down Expand Up @@ -31,15 +32,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 : '<unchanged>',
})
)) {
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 : '<unchanged>'))
console.log('='.repeat(60))

return error
}
Expand Down

0 comments on commit 2313f46

Please sign in to comment.