@cfasim-ui/shared 0.6.4 → 0.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cfasim-ui/shared",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "Shared utilities for cfasim-ui",
6
6
  "license": "Apache-2.0",
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ export type {
14
14
  ModelOutputsWire,
15
15
  } from "./ModelOutput.js";
16
16
  export { modelOutputToCSV } from "./csv.js";
17
+ export { describeWorkerError, MESSAGEERROR_TEXT } from "./workerError.js";
17
18
  export { formatNumber, isNumberFormat } from "./formatNumber.js";
18
19
  export type { NumberFormat, NumberFormatPreset } from "./formatNumber.js";
19
20
  export {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Convert a worker `ErrorEvent` into a human-readable message. Cross-origin
3
+ * worker failures sanitize the event so every field is null/empty (e.g. the
4
+ * worker's module — or a dynamic CDN import inside it — fails to evaluate);
5
+ * fall back to a hint about likely causes rather than an empty string.
6
+ */
7
+ export function describeWorkerError(e: ErrorEvent): string {
8
+ const msg = e.message || e.error?.message || "";
9
+ if (msg) {
10
+ if (e.filename) return `${msg} (${e.filename}:${e.lineno})`;
11
+ return msg;
12
+ }
13
+ return "Worker failed to load (no error details available — most often a cross-origin script load failure or a syntax error in the worker module)";
14
+ }
15
+
16
+ export const MESSAGEERROR_TEXT =
17
+ "Worker received a message it could not deserialize (messageerror)";