Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([codex5-client-error-reporter]): outer try/catch around fetch — sync throw was bypassing the .catch chain
[._.]/ Adam Eivy7d5ac594ae92
diff --git a/client/src/lib/clientErrorReporter.js b/client/src/lib/clientErrorReporter.jsindex 796504b4a0..7e4c9ea33d 100644--- a/client/src/lib/clientErrorReporter.js+++ b/client/src/lib/clientErrorReporter.js@@ -182,12 +182,21 @@ export async function reportClientError(input) {// `keepalive: true` so the POST survives a tab unload triggered by the// crash itself, and we must never throw — an exception inside the// `unhandledrejection` handler would itself become an unhandled rejection.- const ok = await fetch(ENDPOINT, {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: safeBody(payload),- keepalive: true,- }).then(r => r.ok).catch(() => false);+ // Outer try/catch covers a *synchronous* throw from fetch itself (stubbed+ // test globals, CSP-blocked requests that throw before returning a+ // promise); without it the `.then().catch()` chain is never attached and+ // the rejection escapes.+ let ok = false;+ try {+ ok = await fetch(ENDPOINT, {+ method: 'POST',+ headers: { 'Content-Type': 'application/json' },+ body: safeBody(payload),+ keepalive: true,+ }).then(r => r.ok).catch(() => false);+ } catch {+ ok = false;+ }return ok ? { sent: true } : { sent: false, reason: 'transport-error' };}diff --git a/client/src/lib/clientErrorReporter.test.js b/client/src/lib/clientErrorReporter.test.jsindex c4927ee00a..38291d7a13 100644--- a/client/src/lib/clientErrorReporter.test.js+++ b/client/src/lib/clientErrorReporter.test.js@@ -176,4 +176,21 @@ describe('reportClientError', () => {expect(result.sent).toBe(false);expect(result.reason).toBe('transport-error');});++ it('returns transport-error when fetch throws synchronously, never rejects', async () => {+ // CSP-blocked or stubbed-test fetch can throw before returning a promise.+ // Without an outer try/catch the `.then().catch()` chain is never attached+ // and the rejection escapes the global handler.+ globalThis.fetch = vi.fn(() => { throw new Error('sync fetch throw'); });+ let result;+ let rejected = false;+ try {+ result = await reportClientError({ type: 'error', message: 'boom' });+ } catch {+ rejected = true;+ }+ expect(rejected).toBe(false);+ expect(result.sent).toBe(false);+ expect(result.reason).toBe('transport-error');+ });});