mirror of https://github.com/status-im/metro.git
Use `error.message` to set the `description` property of a nested error 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 https://github.com/facebook/metro/pull/125 Differential Revision: D6730671 Pulled By: rafeca fbshipit-source-id: 58311462db9223d65580d77748203d8ea0ea1ac7
This commit is contained in:
parent
b7248380a6
commit
bb93e339fa
|
@ -158,6 +158,7 @@ describe('HmrServer', () => {
|
|||
message: 'test syntax error',
|
||||
errors: [
|
||||
{
|
||||
description: 'test syntax error',
|
||||
filename: 'EntryPoint.js',
|
||||
lineNumber: 123,
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -320,6 +320,7 @@ describe('processRequest', () => {
|
|||
message: 'test syntax error',
|
||||
});
|
||||
expect(body.errors).toContainEqual({
|
||||
description: 'test syntax error',
|
||||
filename: 'testFile.js',
|
||||
lineNumber: 123,
|
||||
});
|
||||
|
|
|
@ -24,7 +24,6 @@ const {
|
|||
export type CustomError = Error & {|
|
||||
status?: number,
|
||||
type?: string,
|
||||
description?: string,
|
||||
filename?: string,
|
||||
lineNumber?: number,
|
||||
errors?: Array<{
|
||||
|
@ -63,7 +62,7 @@ function formatBundlingError(
|
|||
) {
|
||||
error.errors = [
|
||||
{
|
||||
description: error.description,
|
||||
description: error.message,
|
||||
filename: error.filename,
|
||||
lineNumber: error.lineNumber,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue