Skip to content

Commit

Permalink
Use error.message to set the description property of a nested err…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ide committed Jan 15, 2018
1 parent d356c4c commit 7ccad85
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ describe('Transformer', function() {
const babelError = new SyntaxError(message);

babelError.type = 'SyntaxError';
babelError.description = message;
babelError.loc = {line: 2, column: 15};
babelError.codeFrame = snippet;

Expand Down
1 change: 1 addition & 0 deletions packages/metro/src/Server/__tests__/Server-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ describe('processRequest', () => {
message: 'test syntax error',
});
expect(body.errors).toContainEqual({
description: 'test syntax error',
filename: 'testFile.js',
lineNumber: 123,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`getTransformCacheKeyFn Should return always the same key for the same params 1`] = `"19a529ca8ec00ec50dbbf2de5278262868c1a04f32be6252a9bc5b8df65171914db10f84"`;
exports[`getTransformCacheKeyFn Should return always the same key for the same params 1`] = `"19a529ca8ec00ec50dbbf2de5278262868c1a04f22073b63c802f6d42d41280131b93e42"`;
3 changes: 1 addition & 2 deletions packages/metro/src/lib/formatBundlingError.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const {
export type CustomError = Error & {|
status?: number,
type?: string,
description?: string,
filename?: string,
lineNumber?: number,
errors?: Array<{
Expand Down Expand Up @@ -61,7 +60,7 @@ function formatBundlingError(
) {
error.errors = [
{
description: error.description,
description: error.message,
filename: error.filename,
lineNumber: error.lineNumber,
},
Expand Down

0 comments on commit 7ccad85

Please sign in to comment.