1
0
mirror of https://gitlab.com/MisterBiggs/brain-quartz.git synced 2025-06-16 17:56:39 +00:00
fl0werpowers 951d1dec24
chore(deps): replace chalk and rimraf with builtin functions (#1879)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-28 10:40:51 +02:00

44 lines
973 B
TypeScript

import { styleText } from "util"
import process from "process"
import { isMainThread } from "workerpool"
const rootFile = /.*at file:/
export function trace(msg: string, err: Error) {
let stack = err.stack ?? ""
const lines: string[] = []
lines.push("")
lines.push(
"\n" +
styleText(["bgRed", "black", "bold"], " ERROR ") +
"\n\n" +
styleText("red", ` ${msg}`) +
(err.message.length > 0 ? `: ${err.message}` : ""),
)
let reachedEndOfLegibleTrace = false
for (const line of stack.split("\n").slice(1)) {
if (reachedEndOfLegibleTrace) {
break
}
if (!line.includes("node_modules")) {
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)
}
}