From 95573c8b253b71ca2685ac6ecd0dedf8d0765f52 Mon Sep 17 00:00:00 2001 From: orca-bug-scan-bot Date: Tue, 5 May 2026 14:10:46 -0700 Subject: [PATCH] fix: address pr-bug-scan findings from #1385 Wrapped client.optIn() in setOptIn's opt-in branch with try/catch so a rejected optIn no longer skips the telemetry_opted_in event; added .catch() on init-time posthog.optOut() to avoid unhandledRejec --- src/main/telemetry/client.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/telemetry/client.ts b/src/main/telemetry/client.ts index 1885f951dcf..7da34ae3caf 100644 --- a/src/main/telemetry/client.ts +++ b/src/main/telemetry/client.ts @@ -198,7 +198,13 @@ export function initTelemetry(store: Store): void { }) if (shouldOptOutSdkAtInit(resolveConsent(settings))) { - posthog.optOut() + // Why: posthog.optOut() returns a Promise; without a .catch() a + // rejection would surface as an unhandledRejection warning on the + // main process. Mirrors the awaited optOut in setOptIn's finally + // block. + void posthog.optOut().catch((err) => { + console.warn('[telemetry] init-time SDK opt-out failed:', err) + }) } } @@ -358,7 +364,16 @@ export async function setOptIn(via: OptInVia, optedIn: boolean): Promise { return } if (optedIn) { - await client.optIn() + // Why: mirror the opt-out branch's try/catch — a rejected optIn() + // (transient SDK/network) must not propagate and skip the + // telemetry_opted_in audit signal. The persisted opt-in already + // landed via updateSettings above; losing the event would silently + // diverge stored consent from the audit trail. + try { + await client.optIn() + } catch (err) { + console.warn('[telemetry] posthog.optIn() failed; continuing to emit opt-in event:', err) + } track('telemetry_opted_in', { via }) } else { // Fire opt-out event BEFORE disabling the SDK. This is the one event