@oh-my-pi/pi-utils 15.3.2 → 15.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@oh-my-pi/pi-utils",
4
- "version": "15.3.2",
4
+ "version": "15.4.2",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://omp.sh",
7
7
  "author": "Can Boluk",
@@ -31,7 +31,7 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@oh-my-pi/pi-natives": "15.3.2",
34
+ "@oh-my-pi/pi-natives": "15.4.2",
35
35
  "beautiful-mermaid": "^1.1.3",
36
36
  "handlebars": "^4.7.9",
37
37
  "winston": "^3.19.0",
@@ -270,7 +270,7 @@ export function isUnexpectedSocketCloseMessage(message: string): boolean {
270
270
  }
271
271
 
272
272
  const TRANSIENT_MESSAGE_PATTERN =
273
- /overloaded|rate.?limit|too many requests|service.?unavailable|server error|internal error|connection.?error|unable to connect|fetch failed|network error|stream stall|other side closed/i;
273
+ /overloaded|rate.?limit|too many requests|service.?unavailable|server error|internal error|connection.?error|unable to connect|fetch failed|network error|stream stall|other side closed|HTTP2(?:StreamReset|RefusedStream|EnhanceYourCalm)/i;
274
274
 
275
275
  const VALIDATION_MESSAGE_PATTERN =
276
276
  /invalid|validation|bad request|unsupported|schema|missing required|not found|unauthorized|forbidden/i;
package/src/logger.ts CHANGED
@@ -23,6 +23,28 @@ function ensureDir(dir: string): string {
23
23
  return dir;
24
24
  }
25
25
 
26
+ /**
27
+ * JSON.stringify replacer that unwraps {@link Error} instances. Error's own
28
+ * properties are non-enumerable, so a plain `JSON.stringify(err)` produces
29
+ * `"{}"`. Without this, a context like `{ err }` lost every useful field and
30
+ * forensic logs showed only an opaque empty object.
31
+ */
32
+ function jsonReplacer(_key: string, value: unknown): unknown {
33
+ if (value instanceof Error) {
34
+ const out: Record<string, unknown> = {
35
+ name: value.name,
36
+ message: value.message,
37
+ stack: value.stack,
38
+ };
39
+ // Preserve `.cause` and any custom enumerable fields the caller attached.
40
+ const errAsRecord = value as unknown as Record<string, unknown>;
41
+ for (const k in errAsRecord) out[k] = errAsRecord[k];
42
+ if (value.cause !== undefined) out.cause = value.cause;
43
+ return out;
44
+ }
45
+ return value;
46
+ }
47
+
26
48
  /** Custom format that includes pid and flattens metadata */
27
49
  const logFormat = winston.format.combine(
28
50
  winston.format.timestamp({ format: "YYYY-MM-DDTHH:mm:ss.SSSZ" }),
@@ -39,7 +61,7 @@ const logFormat = winston.format.combine(
39
61
  entry[key] = value;
40
62
  }
41
63
  }
42
- return JSON.stringify(entry);
64
+ return JSON.stringify(entry, jsonReplacer);
43
65
  }),
44
66
  );
45
67
 
package/src/postmortem.ts CHANGED
@@ -90,14 +90,14 @@ if (isMainThread) {
90
90
  })
91
91
  .on("uncaughtException", async err => {
92
92
  process.stderr.write(formatFatalError("Uncaught Exception", err));
93
- logger.error("Uncaught exception", { err, stack: err.stack });
93
+ logger.error("Uncaught exception", { err });
94
94
  await runCleanup(Reason.UNCAUGHT_EXCEPTION);
95
95
  process.exit(1);
96
96
  })
97
97
  .on("unhandledRejection", async reason => {
98
98
  const err = reason instanceof Error ? reason : new Error(String(reason));
99
99
  process.stderr.write(formatFatalError("Unhandled Rejection", err));
100
- logger.error("Unhandled rejection", { err, stack: err.stack });
100
+ logger.error("Unhandled rejection", { err });
101
101
  await runCleanup(Reason.UNHANDLED_REJECTION);
102
102
  process.exit(1);
103
103
  })