-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass prod error messages directly to constructor #17063
Conversation
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.
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) ); } ```
React: size: -0.2%, gzip: -0.3% ReactDOM: size: -0.1%, gzip: -0.1% Details of bundled changes.Comparing: 22b2642...e0a97b5 react
react-dom
react-art
react-native-renderer
react-test-renderer
jest-react
react-reconciler
create-subscription
|
779a164
to
e0a97b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a nice cleanup.
`Minified React error #${code}; visit ${url} for the full message or ` + | ||
'use the non-minified dev environment for full errors and additional ' + | ||
'helpful warnings. '; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder why we had a trailing space at the end before and if anything relied on it when appending to the error message. Doesn't look like it was intentional so I assume it's ok :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it was just a mistake :D
Updates the
invariant
transform to pass an error message string directly to the Error constructor, instead of mutating the message property.Turns this code:
into this: