@oh-my-pi/pi-utils 8.3.0 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/postmortem.ts +11 -0
package/package.json
CHANGED
package/src/postmortem.ts
CHANGED
|
@@ -67,6 +67,15 @@ function runCleanup(reason: Reason): Promise<void> {
|
|
|
67
67
|
// Worker thread: exit only (workers use self.addEventListener for exceptions)
|
|
68
68
|
let inspectorOpened = false;
|
|
69
69
|
|
|
70
|
+
function formatFatalError(label: string, err: Error): string {
|
|
71
|
+
const name = err.name || "Error";
|
|
72
|
+
const message = err.message || "(no message)";
|
|
73
|
+
const stack = err.stack || "";
|
|
74
|
+
const stackLines = stack.split("\n").slice(1);
|
|
75
|
+
const formattedStack = stackLines.length > 0 ? `\n${stackLines.join("\n")}` : "";
|
|
76
|
+
return `\n[${label}] ${name}: ${message}${formattedStack}\n`;
|
|
77
|
+
}
|
|
78
|
+
|
|
70
79
|
if (isMainThread) {
|
|
71
80
|
process
|
|
72
81
|
.on("SIGINT", async () => {
|
|
@@ -81,12 +90,14 @@ if (isMainThread) {
|
|
|
81
90
|
process.stderr.write(`Inspector opened: ${url}\n`);
|
|
82
91
|
})
|
|
83
92
|
.on("uncaughtException", async err => {
|
|
93
|
+
process.stderr.write(formatFatalError("Uncaught Exception", err));
|
|
84
94
|
logger.error("Uncaught exception", { err, stack: err.stack });
|
|
85
95
|
await runCleanup(Reason.UNCAUGHT_EXCEPTION);
|
|
86
96
|
process.exit(1);
|
|
87
97
|
})
|
|
88
98
|
.on("unhandledRejection", async reason => {
|
|
89
99
|
const err = reason instanceof Error ? reason : new Error(String(reason));
|
|
100
|
+
process.stderr.write(formatFatalError("Unhandled Rejection", err));
|
|
90
101
|
logger.error("Unhandled rejection", { err, stack: err.stack });
|
|
91
102
|
await runCleanup(Reason.UNHANDLED_REJECTION);
|
|
92
103
|
process.exit(1);
|