diff --git a/react-packager/src/Server/index.js b/react-packager/src/Server/index.js index 2b33f20b..f8113dbb 100644 --- a/react-packager/src/Server/index.js +++ b/react-packager/src/Server/index.js @@ -157,14 +157,16 @@ class Server { } buildBundle(options) { - const opts = bundleOpts(options); - return this._bundler.bundle( - opts.entryFile, - opts.runModule, - opts.sourceMapUrl, - opts.dev, - opts.platform - ); + return Promise.resolve().then(() => { + const opts = bundleOpts(options); + return this._bundler.bundle( + opts.entryFile, + opts.runModule, + opts.sourceMapUrl, + opts.dev, + opts.platform + ); + }); } buildBundleFromUrl(reqUrl) { diff --git a/react-packager/src/SocketInterface/SocketClient.js b/react-packager/src/SocketInterface/SocketClient.js index 32e3b25d..837e7a2c 100644 --- a/react-packager/src/SocketInterface/SocketClient.js +++ b/react-packager/src/SocketInterface/SocketClient.js @@ -33,10 +33,7 @@ class SocketClient { this._sock.on('error', (e) => { e.message = `Error connecting to server on ${sockPath} ` + `with error: ${e.message}`; - - if (fs.existsSync(LOG_PATH)) { - e.message += '\nServer logs:\n' + fs.readFileSync(LOG_PATH, 'utf8'); - } + e.message += getServerLogs(); reject(e); }); @@ -45,8 +42,13 @@ class SocketClient { this._resolvers = Object.create(null); const bunser = new bser.BunserBuf(); this._sock.on('data', (buf) => bunser.append(buf)); - bunser.on('value', (message) => this._handleMessage(message)); + + this._sock.on('close', () => { + if (!this._closing) { + throw new Error('Server closed unexpectedly' + getServerLogs()); + } + }); } onReady() { @@ -105,6 +107,7 @@ class SocketClient { close() { debug('closing connection'); + this._closing = true; this._sock.end(); } } @@ -115,3 +118,11 @@ function uid(len) { len = len || 7; return Math.random().toString(35).substr(2, len); } + +function getServerLogs() { + if (fs.existsSync(LOG_PATH)) { + return '\nServer logs:\n' + fs.readFileSync(LOG_PATH, 'utf8'); + } + + return ''; +} diff --git a/react-packager/src/SocketInterface/SocketServer.js b/react-packager/src/SocketInterface/SocketServer.js index 5778eba0..19b4b29c 100644 --- a/react-packager/src/SocketInterface/SocketServer.js +++ b/react-packager/src/SocketInterface/SocketServer.js @@ -59,7 +59,12 @@ class SocketServer { const bunser = new bser.BunserBuf(); sock.on('data', (buf) => bunser.append(buf)); bunser.on('value', (m) => this._handleMessage(sock, m)); - bunser.on('error', (e) => console.error(e)); + bunser.on('error', (e) => { + e.message = 'Unhandled error from the bser buffer. ' + + 'Either error on encoding or message handling: \n' + + e.message; + throw e; + }); } _handleMessage(sock, m) {