| | |
| | | import chalk from "chalk" |
| | | import { styleText } from "util" |
| | | import process from "process" |
| | | import { isMainThread } from "workerpool" |
| | | |
| | | const rootFile = /.*at file:/ |
| | | export function trace(msg: string, err: Error) { |
| | | const stack = err.stack |
| | | let stack = err.stack ?? "" |
| | | |
| | | const lines: string[] = [] |
| | | |
| | | lines.push("") |
| | | lines.push( |
| | | "\n" + |
| | | chalk.bgRed.black.bold(" ERROR ") + |
| | | "\n" + |
| | | chalk.red(` ${msg}`) + |
| | | styleText(["bgRed", "black", "bold"], " ERROR ") + |
| | | "\n\n" + |
| | | styleText("red", ` ${msg}`) + |
| | | (err.message.length > 0 ? `: ${err.message}` : ""), |
| | | ) |
| | | |
| | | if (!stack) { |
| | | return |
| | | } |
| | | |
| | | let reachedEndOfLegibleTrace = false |
| | | for (const line of stack.split("\n").slice(1)) { |
| | | if (reachedEndOfLegibleTrace) { |