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

Fix RN redbox messages for syntax errors by including error messages in payload #124

Closed
wants to merge 1 commit into from

Conversation

ide
Copy link
Contributor

@ide ide commented Jan 15, 2018

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 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 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.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 15, 2018
@ide ide force-pushed the serialize-error-message branch 2 times, most recently from 3de03df to d356c4c Compare January 15, 2018 21:44
…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.
ide added a commit to expo/react-native that referenced this pull request Jan 15, 2018
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".
@ide
Copy link
Contributor Author

ide commented Jan 16, 2018

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 error.description used to be set and used before, or perhaps something in RN changed recently that now expects Metro to include a message field in the JSON body.

@rafeca Do you think you could take a look at this (you most recently worked on error formatting a few months ago)?

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Jan 16, 2018
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
Copy link
Contributor

@rafeca rafeca left a 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!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

ide added a commit to expo/react-native that referenced this pull request Jan 16, 2018
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
@ide
Copy link
Contributor Author

ide commented Jan 16, 2018

@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.

facebook-github-bot pushed a commit that referenced this pull request Jan 17, 2018
…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
@ide ide deleted the serialize-error-message branch January 17, 2018 02:44
ide added a commit to facebook/react-native that referenced this pull request Jan 18, 2018
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 added a commit to facebook/react-native that referenced this pull request Jan 18, 2018
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
@rafeca
Copy link
Contributor

rafeca commented Jan 19, 2018

@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

@ide
Copy link
Contributor Author

ide commented Feb 13, 2018

Sorry for the late reply - 0.24.5 successfully fixed a specific error message when there was a syntax error with HMR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants