tsc:allowUnreachableCode, eslint:no-unreachable, assert->assertDev
This commit is contained in:
parent
f627a05cf8
commit
eb10aafd7c
57 changed files with 213 additions and 176 deletions
|
@ -22,7 +22,10 @@ export function softAssert(condition: unknown, message: string): void {
|
|||
/**
|
||||
* In production, logs an error and continues. In all other environments, throws an error.
|
||||
*/
|
||||
export function assert(condition: unknown, message: string): asserts condition {
|
||||
export function assertDev(
|
||||
condition: unknown,
|
||||
message: string
|
||||
): asserts condition {
|
||||
if (!condition) {
|
||||
const err = new Error(message);
|
||||
if (getEnvironment() !== Environment.Production) {
|
||||
|
|
|
@ -31,7 +31,7 @@ import { renderClearingDataView } from '../shims/renderClearingDataView';
|
|||
import * as universalExpireTimer from './universalExpireTimer';
|
||||
import { PhoneNumberDiscoverability } from './phoneNumberDiscoverability';
|
||||
import { PhoneNumberSharingMode } from './phoneNumberSharingMode';
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
import * as durations from './durations';
|
||||
import { isPhoneNumberSharingEnabled } from './isPhoneNumberSharingEnabled';
|
||||
import { parseE164FromSignalDotMeHash } from './sgnlHref';
|
||||
|
@ -360,7 +360,7 @@ export function createIPCEvents(
|
|||
const conversationId =
|
||||
window.ConversationController.getOurConversationIdOrThrow();
|
||||
const account = window.ConversationController.get(conversationId);
|
||||
assert(account, "Account wasn't found");
|
||||
assertDev(account, "Account wasn't found");
|
||||
|
||||
account.captureChange('universalExpireTimer');
|
||||
|
||||
|
@ -369,7 +369,7 @@ export function createIPCEvents(
|
|||
const selectedId = state.conversations.selectedConversationId;
|
||||
if (selectedId) {
|
||||
const conversation = window.ConversationController.get(selectedId);
|
||||
assert(conversation, "Conversation wasn't found");
|
||||
assertDev(conversation, "Conversation wasn't found");
|
||||
|
||||
await conversation.updateLastMessage();
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { getOwn } from './getOwn';
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
|
||||
export const deconstructLookup = <T>(
|
||||
lookup: Record<string, T>,
|
||||
|
@ -14,7 +14,7 @@ export const deconstructLookup = <T>(
|
|||
if (value) {
|
||||
result.push(value);
|
||||
} else {
|
||||
assert(false, `deconstructLookup: lookup failed for ${key}; dropping`);
|
||||
assertDev(false, `deconstructLookup: lookup failed for ${key}; dropping`);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import emojiRegex from 'emoji-regex';
|
||||
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
import { take } from './iterables';
|
||||
|
||||
const REGEXP = emojiRegex();
|
||||
|
@ -31,7 +31,7 @@ export function splitByEmoji(value: string): ReadonlyArray<SplitElement> {
|
|||
|
||||
result.push({ type: 'emoji', value: match[0] });
|
||||
|
||||
assert(match.index !== undefined, '`matchAll` should provide indices');
|
||||
assertDev(match.index !== undefined, '`matchAll` should provide indices');
|
||||
lastIndex = match.index + match[0].length;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import type { ProfileRequestDataType } from '../textsecure/WebAPI';
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
import * as Bytes from '../Bytes';
|
||||
import {
|
||||
PaddedLengths,
|
||||
|
@ -27,8 +27,8 @@ export async function encryptProfileData(
|
|||
uuid,
|
||||
} = conversation;
|
||||
|
||||
assert(profileKey, 'profileKey');
|
||||
assert(uuid, 'uuid');
|
||||
assertDev(profileKey, 'profileKey');
|
||||
assertDev(uuid, 'uuid');
|
||||
|
||||
const keyBuffer = Bytes.fromBase64(profileKey);
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { PublicKey, Fingerprint } from '@signalapp/libsignal-client';
|
|||
import type { ConversationType } from '../state/ducks/conversations';
|
||||
import { UUID } from '../types/UUID';
|
||||
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
import * as log from '../logging/log';
|
||||
|
||||
export async function generateSecurityNumber(
|
||||
|
@ -63,7 +63,7 @@ export async function generateSecurityNumberBlock(
|
|||
return [];
|
||||
}
|
||||
|
||||
assert(ourNumber, 'Should have our number');
|
||||
assertDev(ourNumber, 'Should have our number');
|
||||
const securityNumber = await generateSecurityNumber(
|
||||
ourNumber,
|
||||
ourKey,
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
// Copyright 2021-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from './assert';
|
||||
import { assertDev } from './assert';
|
||||
|
||||
export function shouldNeverBeCalled(..._args: ReadonlyArray<unknown>): void {
|
||||
assert(false, 'This should never be called. Doing nothing');
|
||||
assertDev(false, 'This should never be called. Doing nothing');
|
||||
}
|
||||
|
||||
export async function asyncShouldNeverBeCalled(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue