Skip to content
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

Merged
merged 2 commits into from
Oct 11, 2019

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Oct 10, 2019

Updates the invariant transform to pass an error message string directly to the Error constructor, instead of mutating the message property.

Turns this code:

invariant(condition, 'A %s message that contains %s', adj, noun);

into this:

if (!condition) {
  throw Error(
    __DEV__
      ? `A ${adj} message that contains ${noun}`
      : formatProdErrorMessage(ERR_CODE, adj, noun)
  );
}

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)
  );
}
```
@sizebot
Copy link

sizebot commented Oct 10, 2019

React: size: -0.2%, gzip: -0.3%

ReactDOM: size: -0.1%, gzip: -0.1%

Details of bundled changes.

Comparing: 22b2642...e0a97b5

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -0.3% -0.2% 117.71 KB 117.33 KB 29.89 KB 29.83 KB UMD_DEV
react.production.min.js -0.2% -0.3% 12.43 KB 12.4 KB 4.9 KB 4.88 KB UMD_PROD
react.profiling.min.js -0.2% -0.2% 15.94 KB 15.92 KB 5.99 KB 5.98 KB UMD_PROFILING
react.development.js -0.5% -0.3% 72.81 KB 72.43 KB 19.11 KB 19.05 KB NODE_DEV
react.production.min.js -0.4% -0.2% 6.69 KB 6.66 KB 2.78 KB 2.77 KB NODE_PROD
React-dev.js -0.8% -0.4% 70.55 KB 70.01 KB 18.19 KB 18.11 KB FB_WWW_DEV
React-prod.js 🔺+0.1% 0.0% 17.49 KB 17.51 KB 4.58 KB 4.58 KB FB_WWW_PROD
React-profiling.js +0.1% 0.0% 17.49 KB 17.51 KB 4.58 KB 4.58 KB FB_WWW_PROFILING

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js -0.0% -0.0% 119.48 KB 119.46 KB 37.72 KB 37.71 KB NODE_PROFILING
react-dom-server.browser.development.js -0.4% -0.2% 140.69 KB 140.06 KB 36.86 KB 36.8 KB UMD_DEV
ReactDOM-dev.js -0.4% -0.2% 972.8 KB 968.85 KB 215.73 KB 215.29 KB FB_WWW_DEV
react-dom-server.browser.production.min.js -0.1% -0.1% 19.86 KB 19.84 KB 7.38 KB 7.37 KB UMD_PROD
react-dom-test-utils.development.js -0.8% -0.4% 56.76 KB 56.31 KB 15.64 KB 15.59 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.78 KB 3.78 KB 1.53 KB 1.53 KB UMD_DEV
react-dom-test-utils.production.min.js -0.2% -0.5% 11.19 KB 11.17 KB 4.16 KB 4.14 KB UMD_PROD
ReactDOMUnstableNativeDependencies-dev.js -0.9% -0.5% 58.7 KB 58.19 KB 14.86 KB 14.79 KB FB_WWW_DEV
ReactDOMUnstableNativeDependencies-prod.js 🔺+0.1% -0.2% 26.1 KB 26.11 KB 5.27 KB 5.26 KB FB_WWW_PROD
react-dom-test-utils.development.js -0.8% -0.4% 55.04 KB 54.58 KB 15.31 KB 15.25 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% -0.1% 3.61 KB 3.61 KB 1.48 KB 1.48 KB NODE_DEV
react-dom-test-utils.production.min.js -0.2% -0.3% 10.96 KB 10.94 KB 4.09 KB 4.08 KB NODE_PROD
react-dom.development.js -0.2% -0.1% 948.34 KB 946.68 KB 214.54 KB 214.41 KB UMD_DEV
react-dom.production.min.js -0.0% -0.0% 115.72 KB 115.69 KB 37.24 KB 37.24 KB UMD_PROD
ReactTestUtils-dev.js -1.3% -0.6% 52.03 KB 51.35 KB 14.02 KB 13.94 KB FB_WWW_DEV
react-dom.profiling.min.js -0.0% -0.0% 119.24 KB 119.22 KB 38.36 KB 38.35 KB UMD_PROFILING
react-dom.development.js -0.2% -0.1% 942.41 KB 940.75 KB 212.97 KB 212.84 KB NODE_DEV
react-dom-server.node.development.js -0.4% -0.2% 137.71 KB 137.1 KB 36.09 KB 36.02 KB NODE_DEV
react-dom.production.min.js -0.0% -0.0% 115.84 KB 115.81 KB 36.7 KB 36.7 KB NODE_PROD
react-dom-server.node.production.min.js -0.1% -0.2% 20.2 KB 20.17 KB 7.52 KB 7.5 KB NODE_PROD
ReactDOM-prod.js 🔺+0.2% 🔺+0.1% 397.11 KB 398.09 KB 72.39 KB 72.46 KB FB_WWW_PROD
ReactDOM-profiling.js +0.2% +0.1% 397.92 KB 398.88 KB 72.91 KB 72.97 KB FB_WWW_PROFILING
react-dom-server.browser.development.js -0.5% -0.2% 136.62 KB 135.99 KB 35.86 KB 35.8 KB NODE_DEV
react-dom-server.browser.production.min.js -0.1% -0.1% 19.79 KB 19.76 KB 7.36 KB 7.35 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js -0.7% -0.3% 60.53 KB 60.13 KB 15.84 KB 15.79 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js -0.2% -0.3% 10.75 KB 10.72 KB 3.67 KB 3.67 KB UMD_PROD
ReactDOMServer-dev.js -1.0% -0.4% 140.69 KB 139.29 KB 35.48 KB 35.33 KB FB_WWW_DEV
ReactDOMServer-prod.js 🔺+0.5% 🔺+0.3% 48.24 KB 48.5 KB 11.04 KB 11.08 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js -0.7% -0.3% 60.2 KB 59.8 KB 15.71 KB 15.66 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js -0.2% -0.2% 10.49 KB 10.46 KB 3.57 KB 3.57 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% -0.1% 1.1 KB 1.1 KB 668 B 667 B NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js -0.2% -0.1% 668.91 KB 667.62 KB 145.33 KB 145.2 KB UMD_DEV
react-art.production.min.js -0.0% -0.0% 103.65 KB 103.63 KB 31.53 KB 31.51 KB UMD_PROD
react-art.development.js -0.2% -0.1% 599.54 KB 598.25 KB 127.92 KB 127.8 KB NODE_DEV
react-art.production.min.js -0.0% -0.0% 68.67 KB 68.64 KB 20.82 KB 20.81 KB NODE_PROD
ReactART-dev.js -0.5% -0.3% 614.38 KB 611.47 KB 127.78 KB 127.41 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.3% 🔺+0.1% 231.54 KB 232.21 KB 39.1 KB 39.15 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-prod.js -0.9% -0.6% 274.86 KB 272.32 KB 46.99 KB 46.71 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js -0.9% -0.5% 284.39 KB 281.91 KB 48.74 KB 48.47 KB RN_OSS_PROFILING
ReactFabric-prod.js -0.9% -0.6% 266.48 KB 264.1 KB 45.63 KB 45.36 KB RN_OSS_PROD
ReactFabric-profiling.js -0.9% -0.6% 277.13 KB 274.75 KB 47.49 KB 47.22 KB RN_OSS_PROFILING
ReactFabric-dev.js -0.4% -0.3% 750.1 KB 746.85 KB 158.72 KB 158.29 KB RN_FB_DEV
ReactFabric-prod.js -0.9% -0.6% 266.49 KB 264.1 KB 45.65 KB 45.37 KB RN_FB_PROD
ReactNativeRenderer-dev.js -0.4% -0.3% 744.42 KB 741.19 KB 157.82 KB 157.37 KB RN_OSS_DEV
ReactFabric-profiling.js -0.9% -0.6% 277.13 KB 274.75 KB 47.5 KB 47.23 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js -0.4% -0.3% 744.58 KB 741.35 KB 157.89 KB 157.46 KB RN_FB_DEV
ReactNativeRenderer-prod.js -0.9% -0.6% 274.85 KB 272.32 KB 47 KB 46.73 KB RN_FB_PROD
ReactNativeRenderer-profiling.js -0.9% -0.5% 284.38 KB 281.9 KB 48.74 KB 48.49 KB RN_FB_PROFILING
ReactFabric-dev.js -0.4% -0.3% 749.93 KB 746.68 KB 158.65 KB 158.22 KB RN_OSS_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js -0.5% -0.3% 625.7 KB 622.71 KB 130.25 KB 129.89 KB FB_WWW_DEV
react-test-renderer-shallow.development.js -1.0% -0.4% 38.96 KB 38.56 KB 9.94 KB 9.9 KB UMD_DEV
react-test-renderer-shallow.production.min.js -0.2% 🔺+0.1% 11.45 KB 11.43 KB 3.54 KB 3.54 KB UMD_PROD
react-test-renderer-shallow.development.js -1.2% -0.6% 32.92 KB 32.53 KB 8.47 KB 8.42 KB NODE_DEV
react-test-renderer-shallow.production.min.js -0.2% -0.1% 11.6 KB 11.57 KB 3.64 KB 3.63 KB NODE_PROD
react-test-renderer.development.js -0.2% -0.1% 613.32 KB 612.04 KB 130.84 KB 130.75 KB UMD_DEV
react-test-renderer.production.min.js -0.0% -0.1% 70.62 KB 70.6 KB 21.63 KB 21.61 KB UMD_PROD
ReactShallowRenderer-dev.js -1.8% -0.9% 34.04 KB 33.44 KB 8.38 KB 8.31 KB FB_WWW_DEV
react-test-renderer.development.js -0.2% -0.1% 608.59 KB 607.31 KB 129.65 KB 129.55 KB NODE_DEV
react-test-renderer.production.min.js -0.0% -0.1% 70.33 KB 70.3 KB 21.31 KB 21.3 KB NODE_PROD

jest-react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
JestReact-dev.js -7.1% -3.0% 4.99 KB 4.64 KB 1.78 KB 1.72 KB FB_WWW_DEV
jest-react.development.js -4.8% -2.3% 7 KB 6.67 KB 2.55 KB 2.49 KB NODE_DEV
jest-react.production.min.js -1.0% -0.8% 2.57 KB 2.54 KB 1.29 KB 1.28 KB NODE_PROD
JestReact-prod.js -0.9% -0.2% 3.43 KB 3.4 KB 1.26 KB 1.26 KB FB_WWW_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js -0.2% -0.1% 600.49 KB 599.23 KB 127.09 KB 126.97 KB NODE_DEV
react-reconciler.production.min.js -0.0% -0.0% 71.39 KB 71.36 KB 21.1 KB 21.09 KB NODE_PROD
react-reconciler-reflection.development.js -2.0% -0.9% 19.59 KB 19.19 KB 6.32 KB 6.26 KB NODE_DEV
react-reconciler-reflection.production.min.js -0.9% -0.9% 2.88 KB 2.85 KB 1.25 KB 1.24 KB NODE_PROD
react-reconciler-persistent.development.js -0.2% -0.1% 597.84 KB 596.58 KB 125.97 KB 125.85 KB NODE_DEV
react-reconciler-persistent.production.min.js -0.0% -0.0% 71.4 KB 71.37 KB 21.11 KB 21.1 KB NODE_PROD

create-subscription

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
create-subscription.development.js -4.7% -2.3% 7.13 KB 6.79 KB 2.52 KB 2.46 KB NODE_DEV
create-subscription.production.min.js -1.3% -1.0% 2.01 KB 1.98 KB 1004 B 994 B NODE_PROD

Generated by 🚫 dangerJS against e0a97b5

@acdlite acdlite force-pushed the no-mutate-error-messages branch from 779a164 to e0a97b5 Compare October 10, 2019 21:02
@acdlite acdlite requested a review from bvaughn October 10, 2019 21:02
Copy link
Contributor

@bvaughn bvaughn left a 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. ';
Copy link
Contributor

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

Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants