From 4a0c68eacb379e5a82f96dd8adf711ec136a25eb Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Wed, 28 Sep 2022 12:10:49 +0200 Subject: [PATCH] Show detailed errors from the invariant function (in production) --- packages/services/service-common/src/helpers.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/packages/services/service-common/src/helpers.ts b/packages/services/service-common/src/helpers.ts index 6eab2e2eb..29ed67477 100644 --- a/packages/services/service-common/src/helpers.ts +++ b/packages/services/service-common/src/helpers.ts @@ -8,11 +8,9 @@ export function cleanRequestId(requestId?: string | string[] | null): string | u } } -const isProduction: boolean = process.env.NODE_ENV === 'production'; const prefix = 'Invariant failed'; // Throw an error if the condition fails -// Strip out error messages for production // > Not providing an inline default argument for message as the result is smaller export function invariant( condition: unknown, @@ -25,14 +23,7 @@ export function invariant( } // Condition not passed - // In production we strip the message but still throw - if (isProduction) { - throw new Error(prefix); - } - - // When not in production we allow the message to pass through - // *This block will be removed in production builds* - + // We allow the message to pass through const provided: string | undefined = typeof message === 'function' ? message() : message; // Options: