|
1 |
| -The error code system substitutes React's invariant error messages with error IDs to provide a better debugging support in production. Check out the blog post [here](https://reactjs.org/blog/2016/07/11/introducing-reacts-error-code-system.html). |
| 1 | +The error code system substitutes React's error messages with error IDs to |
| 2 | +provide a better debugging support in production. Check out the blog post |
| 3 | +[here](https://reactjs.org/blog/2016/07/11/introducing-reacts-error-code-system.html). |
2 | 4 |
|
3 |
| -## Note for cutting a new React release |
4 |
| -1. For each release, we run `yarn build -- --extract-errors` to update the error codes before calling `yarn build`. The build step uses `codes.json` for a production (minified) build; there should be no warning like `Error message "foo" cannot be found` for a successful release. |
5 |
| -2. The updated `codes.json` file should be synced back to the master branch. The error decoder page in our documentation site uses `codes.json` from master; if the json file has been updated, the docs site should also be rebuilt (`rake copy_error_codes` is included in the default `rake release` task). |
6 |
| -3. Be certain to run `yarn build -- --extract-errors` directly in the release branch (if not master) to ensure the correct error codes are generated. These error messages might be changed/removed before cutting a new release, and we don't want to add intermediate/temporary error messages to `codes.json`. However, if a PR changes an existing error message and there's a specific production test (which is rare), it's ok to update `codes.json` for that. Please use `yarn build -- --extract-errors` and don't edit the file manually. |
7 |
| - |
8 |
| -## Structure |
9 |
| -The error code system consists of 5 parts: |
10 |
| -- [`codes.json`](https://github.com/facebook/react/blob/master/scripts/error-codes/codes.json) contains the mapping from IDs to error messages. This file is generated by the Gulp plugin and is used by both the Babel plugin and the error decoder page in our documentation. This file is append-only, which means an existing code in the file will never be changed/removed. |
11 |
| -- [`extract-errors.js`](https://github.com/facebook/react/blob/master/scripts/error-codes/extract-errors.js) is an node script that traverses our codebase and updates `codes.json`. Use it by calling `yarn build -- --extract-errors`. |
12 |
| -- [`replace-invariant-error-codes.js`](https://github.com/facebook/react/blob/master/scripts/error-codes/replace-invariant-error-codes.js) is a Babel pass that rewrites error messages to IDs for a production (minified) build. |
13 |
| -- [`reactProdInvariant.js`](https://github.com/facebook/react/blob/master/src/shared/utils/reactProdInvariant.js) is the replacement for `invariant` in production. This file gets imported by the Babel plugin and should _not_ be used manually. |
14 |
| -- [`ErrorDecoderComponent`](https://github.com/facebook/react/blob/master/docs/_js/ErrorDecoderComponent.js) is a React component that lives at https://reactjs.org/docs/error-decoder.html. This page takes parameters like `?invariant=109&args[]=Foo` and displays a corresponding error message. Our documentation site's [`Rakefile`](https://github.com/facebook/react/blob/master/docs/Rakefile#L64-L69) has a task (`bundle exec rake copy_error_codes`) for adding the latest `codes.json` to the error decoder page. This task is included in the default `bundle exec rake release` task. |
| 5 | +- [`codes.json`](https://github.com/facebook/react/blob/master/scripts/error-codes/codes.json) |
| 6 | + contains the mapping from IDs to error messages. This file is generated by the |
| 7 | + Gulp plugin and is used by both the Babel plugin and the error decoder page in |
| 8 | + our documentation. This file is append-only, which means an existing code in |
| 9 | + the file will never be changed/removed. |
| 10 | +- [`extract-errors.js`](https://github.com/facebook/react/blob/master/scripts/error-codes/extract-errors.js) |
| 11 | + is an node script that traverses our codebase and updates `codes.json`. You |
| 12 | + can test it by running `yarn build -- --extract-errors`, but you should only |
| 13 | + commit changes to this file when running a release. (The release tool will |
| 14 | + perform this step automatically.) |
| 15 | +- [`minify-error-codes`](https://github.com/facebook/react/blob/master/scripts/error-codes/minify-error-codes) |
| 16 | + is a Babel pass that rewrites error messages to IDs for a production |
| 17 | + (minified) build. |
0 commit comments