mirror of https://github.com/status-im/metro.git
Client should throw when server unexpectedly closes the connection
Reviewed By: @natthu Differential Revision: D2425357
This commit is contained in:
parent
b8209572bb
commit
2c321df75c
|
@ -157,6 +157,7 @@ class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
buildBundle(options) {
|
buildBundle(options) {
|
||||||
|
return Promise.resolve().then(() => {
|
||||||
const opts = bundleOpts(options);
|
const opts = bundleOpts(options);
|
||||||
return this._bundler.bundle(
|
return this._bundler.bundle(
|
||||||
opts.entryFile,
|
opts.entryFile,
|
||||||
|
@ -165,6 +166,7 @@ class Server {
|
||||||
opts.dev,
|
opts.dev,
|
||||||
opts.platform
|
opts.platform
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
buildBundleFromUrl(reqUrl) {
|
buildBundleFromUrl(reqUrl) {
|
||||||
|
|
|
@ -33,10 +33,7 @@ class SocketClient {
|
||||||
this._sock.on('error', (e) => {
|
this._sock.on('error', (e) => {
|
||||||
e.message = `Error connecting to server on ${sockPath} ` +
|
e.message = `Error connecting to server on ${sockPath} ` +
|
||||||
`with error: ${e.message}`;
|
`with error: ${e.message}`;
|
||||||
|
e.message += getServerLogs();
|
||||||
if (fs.existsSync(LOG_PATH)) {
|
|
||||||
e.message += '\nServer logs:\n' + fs.readFileSync(LOG_PATH, 'utf8');
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
|
@ -45,8 +42,13 @@ class SocketClient {
|
||||||
this._resolvers = Object.create(null);
|
this._resolvers = Object.create(null);
|
||||||
const bunser = new bser.BunserBuf();
|
const bunser = new bser.BunserBuf();
|
||||||
this._sock.on('data', (buf) => bunser.append(buf));
|
this._sock.on('data', (buf) => bunser.append(buf));
|
||||||
|
|
||||||
bunser.on('value', (message) => this._handleMessage(message));
|
bunser.on('value', (message) => this._handleMessage(message));
|
||||||
|
|
||||||
|
this._sock.on('close', () => {
|
||||||
|
if (!this._closing) {
|
||||||
|
throw new Error('Server closed unexpectedly' + getServerLogs());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onReady() {
|
onReady() {
|
||||||
|
@ -105,6 +107,7 @@ class SocketClient {
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
debug('closing connection');
|
debug('closing connection');
|
||||||
|
this._closing = true;
|
||||||
this._sock.end();
|
this._sock.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,3 +118,11 @@ function uid(len) {
|
||||||
len = len || 7;
|
len = len || 7;
|
||||||
return Math.random().toString(35).substr(2, len);
|
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 '';
|
||||||
|
}
|
||||||
|
|
|
@ -59,7 +59,12 @@ class SocketServer {
|
||||||
const bunser = new bser.BunserBuf();
|
const bunser = new bser.BunserBuf();
|
||||||
sock.on('data', (buf) => bunser.append(buf));
|
sock.on('data', (buf) => bunser.append(buf));
|
||||||
bunser.on('value', (m) => this._handleMessage(sock, m));
|
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) {
|
_handleMessage(sock, m) {
|
||||||
|
|
Loading…
Reference in New Issue