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

Use error.message to set the description property of a nested error payload #125

Closed
wants to merge 2 commits into from

Conversation

ide
Copy link
Contributor

@ide ide commented Jan 15, 2018

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.

@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 added 2 commits January 15, 2018 15:08
…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.
…or payload

**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.
@ide ide force-pushed the syntax-error-descriptions branch from 7ccad85 to ea45f85 Compare January 15, 2018 23:12
@ide
Copy link
Contributor Author

ide commented Jan 16, 2018

@mjesun This is one place (the last place, I believe) where error.description was left over.

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 ide deleted the syntax-error-descriptions branch January 17, 2018 02:44
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