From a7edca0be8843f3d06ea6886bcdb488195201e3e Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Tue, 26 Nov 2019 13:49:46 +0100 Subject: [PATCH] fix(@embark/core): don't exit in Engine consumer API `Engine.startEngine(cb)` potentially exits the current process if any registered plugins emits an error in the bootstrap phase. This limits consumers of this API to react accordingly. Embark's APIs should be considered library APIs that propagate errors, but let callers decide what to do with them. This commit ensures we keep propagating the error of `startEngine()` without exiting the current process. --- packages/core/core/src/engine.ts | 4 +--- packages/embark/src/cmd/cmd_controller.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/core/core/src/engine.ts b/packages/core/core/src/engine.ts index 6d66591e7..888933e4a 100644 --- a/packages/core/core/src/engine.ts +++ b/packages/core/core/src/engine.ts @@ -116,9 +116,7 @@ export class Engine { if (this.plugins) { this.plugins.emitAndRunActionsForEvent("embark:engine:started", {}, (err) => { if (err) { - console.error("error starting engine"); - console.error(err); - process.exit(1); + return cb(err); } cb(); }); diff --git a/packages/embark/src/cmd/cmd_controller.js b/packages/embark/src/cmd/cmd_controller.js index ac3f3ac2e..93aa39ac7 100644 --- a/packages/embark/src/cmd/cmd_controller.js +++ b/packages/embark/src/cmd/cmd_controller.js @@ -196,7 +196,10 @@ class EmbarkController { engine.events.emit("status", __("Ready").green); }); - engine.startEngine(async () => { + engine.startEngine(async (err) => { + if (err) { + return callback(err); + } callback(); engine.events.request("webserver:start"); @@ -229,8 +232,12 @@ class EmbarkController { } ], function (err, _result) { if (err) { - engine.logger.error(err.message); - engine.logger.info(err.stack); + if (err.message && err.stack) { + engine.logger.error(err.message); + engine.logger.info(err.stack); + } else { + engine.logger.error(err); + } } else { // engine.events.emit('firstDeploymentDone'); }