Show detailed errors from the invariant function (in production)

This commit is contained in:
Kamil Kisiela 2022-09-28 12:10:49 +02:00
parent 01e47d7a1d
commit 4a0c68eacb

View file

@ -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: