From f1c9ca495e450ecb62dade70c4b60d86e106f79c Mon Sep 17 00:00:00 2001
From: vintro <77507980+vintrocode@users.noreply.github.com>
Date: Mon, 14 Aug 2023 00:19:50 +0000
Subject: [PATCH] docs: note about existing content at same path on different branches

---
 quartz/trace.ts |   22 +++++++++++++++++++---
 1 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/quartz/trace.ts b/quartz/trace.ts
index 803fd2f..c7f3cc3 100644
--- a/quartz/trace.ts
+++ b/quartz/trace.ts
@@ -1,16 +1,22 @@
 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(
+
+  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
   }
@@ -22,10 +28,20 @@
     }
 
     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