Skip to content

Commit

Permalink
Catch exceptions in Transformer construction (#351)
Browse files Browse the repository at this point in the history
Summary:
**Summary**

When transformerPath is set in metro.config.js, if there is a failure in loading the custom transformer, the exception is silently swallowed and all the user sees is this misleading error message (see below). In this patch, we add a catch to the promise to report the original exception to the user.

**Test plan**

Set an invalid transformerPath in metro.config.js to reproduce:
```
module.exports = {
  transformerPath: require.resolve('./fail.js'),
}
```

```text
Cannot read property 'transformFile' of undefined

TypeError: Cannot read property 'transformFile' of undefined
    at /Users/go/Library/Application Support/Go Agent/pipelines/ngf-app-ios/node_modules/react-native/node_modules/metro/src/Bundler.js:83:34
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/Users/go/Library/Application Support/Go Agent/pipelines/ngf-app-ios/node_modules/react-native/node_modules/metro/src/Bundler.js:14:24)
    at _next (/Users/go/Library/Application Support/Go Agent/pipelines/ngf-app-ios/node_modules/react-native/node_modules/metro/src/Bundler.js:34:9)
```
Pull Request resolved: #351

Differential Revision: D13898317

Pulled By: rafeca

fbshipit-source-id: 6778b3b96e00a74bf985ea88575f7315a159b77f
  • Loading branch information
sundbry authored and facebook-github-bot committed Jan 31, 2019
1 parent 65f77f2 commit 8cd3654
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/metro/src/Bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ class Bundler {
constructor(config: ConfigT) {
this._depGraphPromise = DependencyGraph.load(config);

this._depGraphPromise.then(dependencyGraph => {
this._transformer = new Transformer(
config,
dependencyGraph.getSha1.bind(dependencyGraph),
);
});
this._depGraphPromise
.then(dependencyGraph => {
this._transformer = new Transformer(
config,
dependencyGraph.getSha1.bind(dependencyGraph),
);
})
.catch(error => {
console.error('Failed to construct transformer: ', error);
});
}

async end() {
Expand Down

0 comments on commit 8cd3654

Please sign in to comment.