mirror of https://github.com/status-im/metro.git
[react-packager] Fail loudly with errors from the transformer
This commit is contained in:
parent
b617c43a03
commit
217f12a08f
|
@ -25,6 +25,9 @@ const MAX_CALLS_PER_WORKER = 600;
|
||||||
// Worker will timeout if one of the callers timeout.
|
// Worker will timeout if one of the callers timeout.
|
||||||
const DEFAULT_MAX_CALL_TIME = 120000;
|
const DEFAULT_MAX_CALL_TIME = 120000;
|
||||||
|
|
||||||
|
// How may times can we tolerate failures from the worker.
|
||||||
|
const MAX_RETRIES = 3;
|
||||||
|
|
||||||
const validateOpts = declareOpts({
|
const validateOpts = declareOpts({
|
||||||
projectRoots: {
|
projectRoots: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
|
@ -63,6 +66,7 @@ class Transformer {
|
||||||
maxConcurrentCallsPerWorker: 1,
|
maxConcurrentCallsPerWorker: 1,
|
||||||
maxCallsPerWorker: MAX_CALLS_PER_WORKER,
|
maxCallsPerWorker: MAX_CALLS_PER_WORKER,
|
||||||
maxCallTime: opts.transformTimeoutInterval,
|
maxCallTime: opts.transformTimeoutInterval,
|
||||||
|
maxRetries: MAX_RETRIES,
|
||||||
}, opts.transformModulePath);
|
}, opts.transformModulePath);
|
||||||
|
|
||||||
this._transform = Promise.denodeify(this._workers);
|
this._transform = Promise.denodeify(this._workers);
|
||||||
|
@ -118,6 +122,13 @@ class Transformer {
|
||||||
);
|
);
|
||||||
timeoutErr.type = 'TimeoutError';
|
timeoutErr.type = 'TimeoutError';
|
||||||
throw timeoutErr;
|
throw timeoutErr;
|
||||||
|
} else if (err.type === 'ProcessTerminatedError') {
|
||||||
|
const uncaughtError = new Error(
|
||||||
|
'Uncaught error in the transformer worker: ' +
|
||||||
|
this._opts.transformModulePath
|
||||||
|
);
|
||||||
|
uncaughtError.type = 'ProcessTerminatedError';
|
||||||
|
throw uncaughtError;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw formatError(err, filePath);
|
throw formatError(err, filePath);
|
||||||
|
|
|
@ -13,6 +13,10 @@ const Promise = require('promise');
|
||||||
const bser = require('bser');
|
const bser = require('bser');
|
||||||
const debug = require('debug')('ReactPackager:SocketClient');
|
const debug = require('debug')('ReactPackager:SocketClient');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
const path = require('path');
|
||||||
|
const tmpdir = require('os').tmpdir();
|
||||||
|
|
||||||
|
const LOG_PATH = path.join(tmpdir, 'react-packager.log');
|
||||||
|
|
||||||
class SocketClient {
|
class SocketClient {
|
||||||
static create(sockPath) {
|
static create(sockPath) {
|
||||||
|
@ -81,7 +85,9 @@ class SocketClient {
|
||||||
delete this._resolvers[message.id];
|
delete this._resolvers[message.id];
|
||||||
|
|
||||||
if (message.type === 'error') {
|
if (message.type === 'error') {
|
||||||
resolver.reject(new Error(message.data));
|
resolver.reject(new Error(
|
||||||
|
message.data + '\n' + 'See logs ' + LOG_PATH
|
||||||
|
));
|
||||||
} else {
|
} else {
|
||||||
resolver.resolve(message.data);
|
resolver.resolve(message.data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,11 @@ class SocketServer {
|
||||||
debug('request error', error);
|
debug('request error', error);
|
||||||
this._jobs--;
|
this._jobs--;
|
||||||
this._reply(sock, m.id, 'error', error.stack);
|
this._reply(sock, m.id, 'error', error.stack);
|
||||||
|
|
||||||
|
// Fatal error from JSTransformer transform workers.
|
||||||
|
if (error.type === 'ProcessTerminatedError') {
|
||||||
|
setImmediate(() => process.exit(1));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (m.type) {
|
switch (m.type) {
|
||||||
|
|
Loading…
Reference in New Issue