feat(@embark/embark-deployment): Don’t hang on contract deploy fail

Prior to this PR (including with v4), Embark would hang on a deployment error.

After this PR, Embark continues it’s run routine despite a contract deployment error, and reports the error to the user in the console appropriately.

NOTE: this branch is based on `refactor/add-contract-tracking` (which would land in https://github.com/embark-framework/embark/pull/1743). If #1743 lands (will be merged in to `refactor_5_0_0`), I will rebase this branch on top of `refactor_5_0_0`.
This commit is contained in:
emizzle 2019-08-07 16:17:48 +10:00 committed by Iuri Matias
parent 10a7833838
commit 29ee9edf83
1 changed files with 21 additions and 16 deletions

View File

@ -15,8 +15,7 @@ class Deployment {
this.contractDeployer = new ContractDeployer({ this.contractDeployer = new ContractDeployer({
events: this.events, events: this.events,
plugins: this.plugins, plugins: this.plugins
logger: this.logger
}); });
this.events.setCommandHandler('deployment:contracts:deploy', (contractsList, contractDependencies, cb) => { this.events.setCommandHandler('deployment:contracts:deploy', (contractsList, contractDependencies, cb) => {
@ -28,17 +27,23 @@ class Deployment {
this.logger.info(__("deploying contracts")); this.logger.info(__("deploying contracts"));
async.waterfall([ async.waterfall([
// TODO used to be called this.plugins.emitAndRunActionsForEvent("deploy:beforeAll", (err) => { // TODO used to be called this.plugins.emitAndRunActionsForEvent("deploy:beforeAll", (err) => {
(next) => {this.plugins.emitAndRunActionsForEvent('deployment:deployContracts:beforeAll', {}, () => {next()});},
(next) => {this.deployAll(contracts, contractDependencies, next);},
(next) => { (next) => {
this.events.emit('contractsDeployed'); this.plugins.emitAndRunActionsForEvent('deployment:deployContracts:beforeAll', {}, (err) => {
this.plugins.emitAndRunActionsForEvent('deployment:deployContracts:afterAll', {}, () => {next()}); next(err);
console.dir("==== finished deploying"); });
},
(next) => {this.deployAll(contracts, contractDependencies, next);},
], (err) => {
if (err) {
this.events.emit("outputError", err.message || err);
this.logger.error(err.message || err);
} }
], done); this.events.emit('contractsDeployed');
this.plugins.emitAndRunActionsForEvent('deployment:deployContracts:afterAll', {}, done);
});
} }
deployContract(contract, errors, callback) { deployContract(contract, callback) {
console.dir("requesting to deploy contract") console.dir("requesting to deploy contract")
this.events.request('deployment:contract:deploy', contract, (err) => { this.events.request('deployment:contract:deploy', contract, (err) => {
if (err) { if (err) {
@ -48,7 +53,7 @@ class Deployment {
} else { } else {
this.logger.error(`[${contract.className}]: ${err.message || err}`); this.logger.error(`[${contract.className}]: ${err.message || err}`);
} }
errors.push(err); return callback(err);
} }
callback(); callback();
}); });
@ -64,7 +69,12 @@ class Deployment {
function deploy(result, callback) { function deploy(result, callback) {
console.dir("== deploy") console.dir("== deploy")
if (typeof result === 'function') callback = result; if (typeof result === 'function') callback = result;
self.deployContract(contract, errors, callback); self.deployContract(contract, (err) => {
if (err) {
errors.push(err);
}
callback();
});
} }
const className = contract.className; const className = contract.className;
@ -77,13 +87,8 @@ class Deployment {
}) })
async.auto(contractDeploys, (err, _results) => { async.auto(contractDeploys, (err, _results) => {
if (err) {
console.dir("error deploying contracts")
console.dir(err)
}
if (errors.length) { if (errors.length) {
err = __("Error deploying contracts. Please fix errors to continue."); err = __("Error deploying contracts. Please fix errors to continue.");
this.events.emit("outputError", __("Error deploying contracts, please check console"));
return done(err); return done(err);
} }
if (contracts.length === 0) { if (contracts.length === 0) {