(asyncResource, logger)
| 54 | } |
| 55 | |
| 56 | function 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 | |
| 87 | function formatLocation (stack) { |
| 88 | const filePath = formatFilePath(stack.fileName) |
no test coverage detected
searching dependent graphs…