mirror of
https://github.com/stablyai/orca.git
synced 2026-10-13 08:02:52 +00:00
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
This commit is contained in:
@@ -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<void> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user