(error: Error)
| 52 | * For an error instance, return its stack frames as an array. |
| 53 | */ |
| 54 | export const getFramesFromError = (error: Error): string[] => { |
| 55 | // Create an error |
| 56 | let stack: Error["stack"] | null, frames: any[] |
| 57 | |
| 58 | // And attempt to retrieve it's stack |
| 59 | // https://github.com/winstonjs/winston/issues/401#issuecomment-61913086 |
| 60 | try { |
| 61 | stack = error.stack |
| 62 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 63 | } catch (error1) { |
| 64 | try { |
| 65 | // @ts-expect-error https://github.com/winstonjs/winston/issues/401#issuecomment-61913086 |
| 66 | const previous = err.__previous__ || err.__previous |
| 67 | stack = previous && previous.stack |
| 68 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 69 | } catch (error2) { |
| 70 | stack = null |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Handle different stack formats |
| 75 | if (stack) |
| 76 | frames = Array.isArray(stack) ? Array(stack) : stack.toString().split("\n") |
| 77 | else frames = [] |
| 78 | |
| 79 | // Parse our frames |
| 80 | return frames |
| 81 | } |
| 82 | |
| 83 | const lineRegex = |
| 84 | /\s+at\s(?:(?<method>.+?)\s\()?(?<file>.+?):(?<line>\d+):(?<char>\d+)\)?\s*$/ |
no test coverage detected