Jacky Zhao
2023-08-06 a0d651d64dfd766157324fd86791da2168028cf2
quartz/trace.ts
@@ -1,16 +1,23 @@
import chalk from "chalk"
import process from "process"
const rootFile = /.*at file:/
export function trace(msg: string, err: Error) {
  const stack = err.stack
  console.log()
  console.log(chalk.bgRed.white.bold(" ERROR ") + chalk.red(` ${msg}`) + (err.message.length > 0 ? `: ${err.message}` : ""))
  console.log(
    "\n" +
      chalk.bgRed.black.bold(" ERROR ") +
      "\n" +
      chalk.red(` ${msg}`) +
      (err.message.length > 0 ? `: ${err.message}` : ""),
  )
  if (!stack) {
    return
  }
  let reachedEndOfLegibleTrace = false
  for (const line of stack.split('\n').slice(1)) {
  for (const line of stack.split("\n").slice(1)) {
    if (reachedEndOfLegibleTrace) {
      break
    }
@@ -22,4 +29,5 @@
      }
    }
  }
  process.exit(1)
}