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 | 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