Handle transform problems correctly

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
This commit is contained in:
David Aurelio 2016-11-18 20:35:16 -08:00 committed by Facebook Github Bot
parent a477aec10d
commit a10eee4372
1 changed files with 18 additions and 13 deletions

View File

@ -223,8 +223,9 @@ 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)
this._readSourceCode()
.then(sourceCode =>
_transformCode(this, sourceCode, transformOptions)
.then(freshResult => {
TransformCache.writeSync({
filePath: this.path,
@ -233,9 +234,13 @@ class Module {
transformOptions,
result: freshResult,
});
callback(undefined, freshResult);
});
}, callback);
return freshResult;
})
)
.then(
freshResult => process.nextTick(callback, null, freshResult),
error => process.nextTick(callback, error),
);
}
/**