From a10eee4372d94c5272406e1b2f507ec98b5a4e03 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Fri, 18 Nov 2016 20:35:16 -0800 Subject: [PATCH] Handle transform problems correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: This fixes a piece of promise code that didn’t handle nested rejections. This caused the packager not to recover from transform errors, as the server was waiting for an in-limbo promise forever. Reviewed By: cpojer Differential Revision: D4207138 fbshipit-source-id: 8e94ddebd033073f90b79b1c4820c09ac98a4932 --- .../react-packager/src/node-haste/Module.js | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/packager/react-packager/src/node-haste/Module.js b/packager/react-packager/src/node-haste/Module.js index 4b8072e75..8a4ceab95 100644 --- a/packager/react-packager/src/node-haste/Module.js +++ b/packager/react-packager/src/node-haste/Module.js @@ -223,19 +223,24 @@ class Module { // never be transformed anyway. invariant(_transformCode != null, 'missing code transform funtion'); invariant(_transformCacheKey != null, 'missing cache key'); - this._readSourceCode().then(sourceCode => { - return _transformCode(this, sourceCode, transformOptions) - .then(freshResult => { - TransformCache.writeSync({ - filePath: this.path, - sourceCode, - transformCacheKey: _transformCacheKey, - transformOptions, - result: freshResult, - }); - callback(undefined, freshResult); - }); - }, callback); + this._readSourceCode() + .then(sourceCode => + _transformCode(this, sourceCode, transformOptions) + .then(freshResult => { + TransformCache.writeSync({ + filePath: this.path, + sourceCode, + transformCacheKey: _transformCacheKey, + transformOptions, + result: freshResult, + }); + return freshResult; + }) + ) + .then( + freshResult => process.nextTick(callback, null, freshResult), + error => process.nextTick(callback, error), + ); } /**