diff --git a/ts/util/assert.ts b/ts/util/assert.ts index 4827974085fb..285a5e52f92f 100644 --- a/ts/util/assert.ts +++ b/ts/util/assert.ts @@ -5,16 +5,22 @@ import { getEnvironment, Environment } from '../environment'; import * as log from '../logging/log'; import * as Errors from '../types/errors'; +/** + * In development, starts the debugger. + */ +export function devDebugger(): void { + if (getEnvironment() === Environment.Development) { + debugger; // eslint-disable-line no-debugger + } +} + /** * In production and beta, logs a warning and continues. For development it * starts the debugger. */ export function softAssert(condition: unknown, message: string): void { if (!condition) { - if (getEnvironment() === Environment.Development) { - debugger; // eslint-disable-line no-debugger - } - + devDebugger(); const err = new Error(message); log.warn('softAssert failure:', Errors.toLogFormat(err)); } @@ -30,9 +36,7 @@ export function assertDev( if (!condition) { const err = new Error(message); if (getEnvironment() !== Environment.PackagedApp) { - if (getEnvironment() === Environment.Development) { - debugger; // eslint-disable-line no-debugger - } + devDebugger(); throw err; } log.error('assert failure:', Errors.toLogFormat(err)); diff --git a/ts/util/groupSendEndorsements.ts b/ts/util/groupSendEndorsements.ts index 7a9d8f67399f..3dc16213deb7 100644 --- a/ts/util/groupSendEndorsements.ts +++ b/ts/util/groupSendEndorsements.ts @@ -11,7 +11,7 @@ import { toGroupSendToken, type GroupSendEndorsementsData, } from '../types/GroupSendEndorsements'; -import { assertDev, strictAssert } from './assert'; +import { devDebugger, strictAssert } from './assert'; import { GroupSecretParams, GroupSendEndorsement, @@ -277,5 +277,5 @@ export function onFailedToSendWithEndorsements(error: Error): void { if (window.SignalCI) { window.SignalCI.handleEvent('fatalTestError', error); } - assertDev(false, 'We should never fail to send with endorsements'); + devDebugger(); } diff --git a/ts/util/sendToGroup.ts b/ts/util/sendToGroup.ts index 6d2eda9a7ed6..3964c9b0cf74 100644 --- a/ts/util/sendToGroup.ts +++ b/ts/util/sendToGroup.ts @@ -1477,13 +1477,13 @@ async function fetchKeysForServiceId( await DataWriter.updateConversation(emptyConversation.attributes); } } catch (error: unknown) { - if (useGroupSendEndorsement) { - onFailedToSendWithEndorsements(error as Error); - } if (error instanceof UnregisteredUserError) { await markServiceIdUnregistered(serviceId); return; } + if (useGroupSendEndorsement) { + onFailedToSendWithEndorsements(error as Error); + } log.error( `fetchKeysForServiceId: Error fetching ${ devices || 'all'