Skip to content

Commit

Permalink
Wrap require in Worker with try-catch
Browse files Browse the repository at this point in the history
Worker._run in async, so throws in it will result in unhandled Promise rejection instead of unhandled exception, and process wont exit.
  • Loading branch information
mcheshkov committed Jun 28, 2018
1 parent 1ec9886 commit f7f90c1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ class Worker extends ClusterProcess {

const workerBase = this.config.resolve('app');

require(workerBase);
try {
require(workerBase);
} catch (e) {
console.error(`Worker failed on require ${workerBase}`);
console.error(e);
process.exit(1);
}
this.emit('loaded', workerBase);

if (!this.config.get('control.triggerReadyStateManually', false)) {
Expand Down

0 comments on commit f7f90c1

Please sign in to comment.