export-runtime 0.0.23 → 0.0.24

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/handler.js +39 -27
  2. package/package.json +1 -1
package/handler.js CHANGED
@@ -343,41 +343,53 @@ export const createHandler = (moduleMap, generatedTypes, minifiedCore, coreId, m
343
343
  };
344
344
 
345
345
  server.addEventListener("message", (event) => {
346
- if (isClosed) return;
346
+ // Wrap entire handler in try-catch to prevent any unhandled errors
347
+ try {
348
+ if (isClosed) return;
347
349
 
348
- // Handle message asynchronously - fire and forget
349
- (async () => {
350
+ // Parse message synchronously to get the id
351
+ let msg;
350
352
  let id;
351
353
  try {
352
- if (isClosed) return;
353
- const msg = parse(event.data);
354
+ msg = parse(event.data);
354
355
  id = msg.id;
356
+ } catch {
357
+ return;
358
+ }
355
359
 
356
- // Handle auth token updates (on reconnect or explicit setToken)
357
- if (msg.type === "auth" && msg.token && !msg.method) {
358
- wsSession.token = msg.token;
359
- safeSend(stringify({ type: "auth-result", id, success: true }));
360
- return;
361
- }
362
-
363
- if (isClosed) return;
364
- const result = await dispatchMessage(dispatcher, msg, env, wsSession);
360
+ // Handle ping synchronously - no async needed
361
+ if (msg.type === "ping") {
362
+ safeSend(stringify({ type: "pong", id }));
363
+ return;
364
+ }
365
365
 
366
- if (isClosed) return;
366
+ // Handle auth token updates synchronously
367
+ if (msg.type === "auth" && msg.token && !msg.method) {
368
+ wsSession.token = msg.token;
369
+ safeSend(stringify({ type: "auth-result", id, success: true }));
370
+ return;
371
+ }
367
372
 
368
- // Extract token from auth responses
369
- if (result?.value?.token && msg.type === "auth") {
370
- wsSession.token = result.value.token;
373
+ // Handle other messages asynchronously with full error protection
374
+ (async () => {
375
+ try {
376
+ if (isClosed) return;
377
+ const result = await dispatchMessage(dispatcher, msg, env, wsSession);
378
+ if (isClosed) return;
379
+
380
+ // Extract token from auth responses
381
+ if (result?.value?.token && msg.type === "auth") {
382
+ wsSession.token = result.value.token;
383
+ }
384
+
385
+ if (result) safeSend(stringify({ ...result, id }));
386
+ } catch {
387
+ // Silently ignore all errors - connection may be closing
371
388
  }
372
-
373
- if (result) safeSend(stringify({ ...result, id }));
374
- } catch (err) {
375
- if (isClosed) return;
376
- const errStr = String(err);
377
- if (errStr.includes("Connection closed") || errStr.includes("WebSocket")) return;
378
- if (id !== undefined) safeSend(stringify({ type: "error", id, error: errStr }));
379
- }
380
- })();
389
+ })().catch(() => {}); // Double-catch to ensure no unhandled promise rejection
390
+ } catch {
391
+ // Silently ignore outer errors too
392
+ }
381
393
  });
382
394
 
383
395
  server.addEventListener("close", handleClose);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "export-runtime",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "Cloudflare Workers ESM Export Framework Runtime",
5
5
  "keywords": [
6
6
  "cloudflare",