@zhushanwen/pi-ext-guards 0.2.0 → 0.2.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.ts +11 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-ext-guards",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared runtime-environment guards for Pi extensions — oncePerProcess(key, fn) dedupes cross-session side-effect operations against pi factory re-invocation and handler accumulation (shared library, not a Pi extension, zero dependencies).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -71,3 +71,14 @@ export function oncePerProcess<T>(key: string, fn: () => T): T {
71
71
  throw error;
72
72
  }
73
73
  }
74
+
75
+ /**
76
+ * 从任意 thrown 值提取可读的错误信息字符串:Error → `.message`,其它 → `String(value)`。
77
+ *
78
+ * 收敛各 extension 包散落的 `e instanceof Error ? e.message : String(e)` 样板
79
+ * (与 core/renderer/runtime/subagent-core/electron 各自持有的同名 helper 同实现——
80
+ * 本包是 extensions 体系的共享归宿,业务包不再各自内联)。
81
+ */
82
+ export function toErrorMessage(e: unknown): string {
83
+ return e instanceof Error ? e.message : String(e);
84
+ }