From 85ae41eb1c161223d9166bc780f8bfea34c12143 Mon Sep 17 00:00:00 2001 From: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com> Date: Tue, 1 Feb 2022 18:57:31 -0600 Subject: [PATCH] Remove duplicate helper function from `missingCaseError` --- ts/util/missingCaseError.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/ts/util/missingCaseError.ts b/ts/util/missingCaseError.ts index a4876bec4..6021b2523 100644 --- a/ts/util/missingCaseError.ts +++ b/ts/util/missingCaseError.ts @@ -1,16 +1,7 @@ -// Copyright 2018-2020 Signal Messenger, LLC +// Copyright 2018-2022 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only -const stringify = (value: unknown): string => { - try { - // `JSON.stringify` can return `undefined` (TypeScript has incorrect types here). - // However, this is fine because we interpolate it into a string, so it shows up as - // "undefined" in the final error message. - return JSON.stringify(value); - } catch (err) { - return Object.prototype.toString.call(value); - } -}; +import { reallyJsonStringify } from './reallyJsonStringify'; // `missingCaseError` is useful for compile-time checking that all `case`s in // a `switch` statement have been handled, e.g. @@ -32,4 +23,4 @@ const stringify = (value: unknown): string => { // handled by our `switch` / `case` statement which is useful for code // maintenance and system evolution. export const missingCaseError = (x: never): TypeError => - new TypeError(`Unhandled case: ${stringify(x)}`); + new TypeError(`Unhandled case: ${reallyJsonStringify(x)}`);