-
Notifications
You must be signed in to change notification settings - Fork 637
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
Fix RN redbox messages for syntax errors by including error messages in payload #124
Conversation
3de03df
to
d356c4c
Compare
…in payload With RN 0.52, when there was a redbox due to a syntax error in a source file (with regular, non-delta bundler), the redbox would say just "No message provided". The JSON that Metro sent to RN did not include a "message" field because `JSON.stringify(error)` does not include `message`. Test Plan: Add a syntax error to one of the files in RNTester's JS and load the RNTester app (from RN master). See that the redbox now says there was a transform error with info about where the syntax error is. Also tested adding a syntax error with HMR enabled and saw that the error `message` field was set in the payload as expected. Also added a Jest test to Server-test.js.
d356c4c
to
6d5878d
Compare
The code to display HMR errors on the client was reading the `description` field from Metro payloads. Metro does not include `description` in the body of its error payloads -- only in its `body.errors[]` items. This commit changes RN's HMR code to show `body.message` (set consistently with facebook/metro#124) instead of the non-existent `body.description`. Test Plan: Open a test RN app, enable HMR, and then introduce a syntax error in an app source file. See that the redbox provides information about the syntax error instead of just saying "TransformError undefined".
This code (JSON.stringifying an error) goes back more than three years so I don't think the original author has the same context. My guess is that @rafeca Do you think you could take a look at this (you most recently worked on error formatting a few months ago)? |
Summary: The code to display HMR errors on the client was reading the `description` field from Metro payloads. Metro does not include `description` in the body of its error payloads -- only in its `body.errors[]` items. This commit changes RN's HMR code to show `body.message` (set consistently with facebook/metro#124) instead of the non-existent `body.description`. Open a test RN app, enable HMR, and then introduce a syntax error in an app source file. See that the redbox provides information about the syntax error instead of just saying "TransformError undefined". - facebook/metro#124 [GENERAL][ENHANCEMENT][HMR] - Fix display of syntax error messages when HMR is enabled Closes #17619 Differential Revision: D6726516 Pulled By: mjesun fbshipit-source-id: b1d1008d6f1aa8f88ff8a2aa1374724a305c773b
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.
Thanks for fixing this!
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.
@rafeca is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: The code to display HMR errors on the client was reading the `description` field from Metro payloads. Metro does not include `description` in the body of its error payloads -- only in its `body.errors[]` items. This commit changes RN's HMR code to show `body.message` (set consistently with facebook/metro#124) instead of the non-existent `body.description`. Open a test RN app, enable HMR, and then introduce a syntax error in an app source file. See that the redbox provides information about the syntax error instead of just saying "TransformError undefined". - facebook/metro#124 [GENERAL][ENHANCEMENT][HMR] - Fix display of syntax error messages when HMR is enabled Closes facebook#17619 Differential Revision: D6726516 Pulled By: mjesun fbshipit-source-id: b1d1008d6f1aa8f88ff8a2aa1374724a305c773b
@rafeca Could I ask you to publish 0.24.5 after this lands? I think (hoping...) this is the last commit we need to show TransformError messages in create-react-native-app for RN 0.52. |
…or payload Summary: Depends on #124. --- **Summary** Metro reports errors using a JSON payload that has an `errors` array. Each item in this array has a `description` field. For transform errors, this field was set using the value in `error.description` -- however, JS Error objects only have a `message` field. (Grepping the Metro code, no errors (except in one test) ever get a `description` field.) This commit uses `error.message` instead of `error.description` when creating JSON payloads. ``` $ git grep description -- 'packages/**/*.js' packages/metro/src/JSTransformer/__tests__/Transformer-test.js: babelError.description = message; packages/metro/src/lib/formatBundlingError.js: description: string, packages/metro/src/lib/formatBundlingError.js:): {type: string, message: string, errors: Array<{description: string}>} { packages/metro/src/lib/formatBundlingError.js: errors: [{description: message}], packages/metro/src/lib/formatBundlingError.js: description: error.message, packages/metro/src/node-haste/__tests__/Module-test.js: description: "A require('foo') story", ``` **Test Plan** Added a unit test to check that the description field is set for transform errors (with the delta bundler). Also in a test RN app, inspected the error payload that is received by RN when there's a syntax error with HMR turned on and verified that `data.body.errors[0].description` was set. Closes #125 Differential Revision: D6730671 Pulled By: rafeca fbshipit-source-id: 58311462db9223d65580d77748203d8ea0ea1ac7
Summary: The code to display HMR errors on the client was reading the `description` field from Metro payloads. Metro does not include `description` in the body of its error payloads -- only in its `body.errors[]` items. This commit changes RN's HMR code to show `body.message` (set consistently with facebook/metro#124) instead of the non-existent `body.description`. Open a test RN app, enable HMR, and then introduce a syntax error in an app source file. See that the redbox provides information about the syntax error instead of just saying "TransformError undefined". - facebook/metro#124 [GENERAL][ENHANCEMENT][HMR] - Fix display of syntax error messages when HMR is enabled Closes #17619 Differential Revision: D6726516 Pulled By: mjesun fbshipit-source-id: b1d1008d6f1aa8f88ff8a2aa1374724a305c773b
Summary: The code to display HMR errors on the client was reading the `description` field from Metro payloads. Metro does not include `description` in the body of its error payloads -- only in its `body.errors[]` items. This commit changes RN's HMR code to show `body.message` (set consistently with facebook/metro#124) instead of the non-existent `body.description`. Open a test RN app, enable HMR, and then introduce a syntax error in an app source file. See that the redbox provides information about the syntax error instead of just saying "TransformError undefined". - facebook/metro#124 [GENERAL][ENHANCEMENT][HMR] - Fix display of syntax error messages when HMR is enabled Closes #17619 Differential Revision: D6726516 Pulled By: mjesun fbshipit-source-id: b1d1008d6f1aa8f88ff8a2aa1374724a305c773b
@ide we've just published 0.24.5 (we wanted to add a few more things to this release, this is why it took a few days). Let me know if this fixes all the issues in create-react-native-app |
Sorry for the late reply - 0.24.5 successfully fixed a specific error message when there was a syntax error with HMR. |
Summary
With RN 0.52, when there was a redbox due to a syntax error in a source file (with regular, non-delta bundler), the redbox would say just "No message provided". The JSON that Metro sent to RN did not include a "message" field because
JSON.stringify(error)
does not includemessage
.Test Plan
Add a syntax error to one of the files in RNTester's JS and load the RNTester app (from RN master). See that the redbox now says there was a transform error with the syntax error's location.
Also tested adding a syntax error with HMR enabled and saw that the error
message
field was set in the payload as expected.Also added a Jest test to Server-test.js.