dillon1000/react
Commit
Browse files Pass prod error messages directly to constructor (#17063)
* Remove "Invariant Violation" from dev errors
When I made the change to compile `invariant` to throw expressions, I
left a small runtime to set the error's `name` property to "Invariant
Violation" to maintain the existing behavior.
I think we can remove it. The argument for keeping it is to preserve
continuity in error logs, but this only affects development errors,
anyway: production error messages are replaced with error codes.
* Pass prod error messages directly to constructor
Updates the `invariant` transform to pass an error message string
directly to the Error constructor, instead of mutating the
message property.
Turns this code:
```js
invariant(condition, 'A %s message that contains %s', adj, noun);
```
into this:
```js
if (!condition) {
throw Error(
__DEV__
? `A ${adj} message that contains ${noun}`
: formatProdErrorMessage(ERR_CODE, adj, noun)
);
}
```Changed paths7 files
First-parent comparisonpackages/react-native-renderer/src/__tests__/ReactNativeError-test.internal.js ModifiedD packages/shared/ReactError.js DeletedM packages/shared/__tests__/ReactError-test.internal.js ModifiedM packages/shared/__tests__/ReactErrorProd-test.internal.js ModifiedR packages/shared/ReactErrorProd.js →packages/shared/formatProdErrorMessage.js RenamedM scripts/error-codes/__tests__/__snapshots__/transform-error-messages.js.snap ModifiedM scripts/error-codes/transform-error-messages.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…