MCPcopy
hub / github.com/mafintosh/why-is-node-running / printStacks

Function printStacks

index.js:56–85  ·  view source on GitHub ↗
(asyncResource, logger)

Source from the content-addressed store, hash-verified

54}
55
56function printStacks (asyncResource, logger) {
57 const stacks = asyncResource.stacks.filter((stack) => {
58 const fileName = stack.fileName
59 return fileName !== null && !fileName.startsWith('node:')
60 })
61
62 logger.error('')
63 logger.error(`# ${asyncResource.type}`)
64
65 if (!stacks[0]) {
66 logger.error('(unknown stack trace)')
67 return
68 }
69
70 const maxLength = stacks.reduce((length, stack) => Math.max(length, formatLocation(stack).length), 0)
71
72 for (const stack of stacks) {
73 const location = formatLocation(stack)
74 const padding = ' '.repeat(maxLength - location.length)
75
76 try {
77 const lines = readFileSync(normalizeFilePath(stack.fileName), 'utf-8').split(/\n|\r\n/)
78 const line = lines[stack.lineNumber - 1].trim()
79
80 logger.error(`${location}${padding} - ${line}`)
81 } catch (e) {
82 logger.error(`${location}${padding}`)
83 }
84 }
85}
86
87function formatLocation (stack) {
88 const filePath = formatFilePath(stack.fileName)

Callers 1

whyIsNodeRunningFunction · 0.85

Calls 3

formatLocationFunction · 0.85
normalizeFilePathFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…