From 49bd6bc3ffe1d3507e00bae62c12d9b045363090 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Wed, 09 Aug 2023 05:52:49 +0000
Subject: [PATCH] better concurrency debugging, --concurrency flag for npx quartz build
---
quartz/trace.ts | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/quartz/trace.ts b/quartz/trace.ts
index 337ffe0..ca3a5a0 100644
--- a/quartz/trace.ts
+++ b/quartz/trace.ts
@@ -1,17 +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}` : ""),
+ chalk.bgRed.black.bold(" ERROR ") +
+ "\n" +
+ chalk.red(` ${msg}`) +
+ (err.message.length > 0 ? `: ${err.message}` : ""),
)
+
if (!stack) {
return
}
@@ -23,11 +28,20 @@
}
if (!line.includes("node_modules")) {
- console.log(` ${line}`)
+ lines.push(` ${line}`)
if (rootFile.test(line)) {
reachedEndOfLegibleTrace = true
}
}
}
- process.exit(1)
+
+ 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