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.
This commit is contained in:
Pascal Precht 2019-11-26 13:49:46 +01:00 committed by Pascal Precht
parent 5f33b93b31
commit a7edca0be8
2 changed files with 11 additions and 6 deletions

View File

@ -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();
});

View File

@ -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');
}