From df02ea20d7e12e8b9ffdd2968afaf5893c433488 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Fri, 11 Aug 2023 04:32:11 +0000
Subject: [PATCH] spacing fix

---
 quartz/trace.ts |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/quartz/trace.ts b/quartz/trace.ts
index 47f9638..c7f3cc3 100644
--- a/quartz/trace.ts
+++ b/quartz/trace.ts
@@ -1,25 +1,47 @@
 import chalk from "chalk"
+import process from "process"
+import { isMainThread } from "workerpool"
 
 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}` : ""))
+
+  const lines: string[] = []
+
+  lines.push("")
+  lines.push(
+    "\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
     }
 
     if (!line.includes("node_modules")) {
-      console.log(` ${line}`)
+      lines.push(` ${line}`)
       if (rootFile.test(line)) {
         reachedEndOfLegibleTrace = true
       }
     }
   }
+
+  const traceMsg = lines.join("\n")
+  if (!isMainThread) {
+    // gather lines and throw
+    throw new Error(traceMsg)
+  } else {
+    // print and exit
+    console.error(traceMsg)
+    process.exit(1)
+  }
 }

--
Gitblit v1.10.0