From c8b52a17466105737dab5a99f087355b03ecf6d1 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 8 Jun 2018 07:07:27 -0400 Subject: [PATCH] fix errors handling so it doesn't attempt to continue building when there are fatal errors compiling contracts --- lib/contracts/code_generator.js | 8 ++++---- lib/contracts/contract_deployer.js | 2 +- lib/contracts/contracts.js | 11 ++++++++--- lib/contracts/deploy_manager.js | 15 ++++++++++----- lib/index.js | 7 +++++-- lib/pipeline/pipeline.js | 6 +++--- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js index 964a54ff9..9a02f519e 100644 --- a/lib/contracts/code_generator.js +++ b/lib/contracts/code_generator.js @@ -43,7 +43,7 @@ class CodeGenerator { // new events this.events.setCommandHandler('code-vanila', function(cb) { - self.events.request("contracts:list", (contractsList) => { + self.events.request("contracts:list", (_err, contractsList) => { let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); @@ -51,7 +51,7 @@ class CodeGenerator { }); this.events.setCommandHandler('code', function(cb) { - self.events.request("contracts:list", (contractsList) => { + self.events.request("contracts:list", (_err, contractsList) => { let embarkJSABI = self.generateABI(contractsList, {useEmbarkJS: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(embarkJSABI, contractsJSON); @@ -59,7 +59,7 @@ class CodeGenerator { }); this.events.setCommandHandler('code-contracts-vanila', function(cb) { - self.events.request("contracts:list", (contractsList) => { + self.events.request("contracts:list", (_err, contractsList) => { let vanillaContractsABI = self.generateContracts(contractsList, false, true, false); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaContractsABI, contractsJSON); @@ -67,7 +67,7 @@ class CodeGenerator { }); this.events.setCommandHandler('code-vanila-deployment', function(cb) { - self.events.request("contracts:list", (contractsList) => { + self.events.request("contracts:list", (_err, contractsList) => { let vanillaABI = self.generateABI(contractsList, {useEmbarkJS: false, deployment: true}); let contractsJSON = self.generateContractsJSON(contractsList); cb(vanillaABI, contractsJSON); diff --git a/lib/contracts/contract_deployer.js b/lib/contracts/contract_deployer.js index 7ffce6d9c..546012c8c 100644 --- a/lib/contracts/contract_deployer.js +++ b/lib/contracts/contract_deployer.js @@ -170,7 +170,7 @@ class ContractDeployer { }); }, function doLinking(next) { - self.events.request('contracts:list', (contracts) => { + self.events.request('contracts:list', (_err, contracts) => { for (let contractObj of contracts) { let filename = contractObj.filename; let deployedAddress = contractObj.deployedAddress; diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 5c389723a..b74b7f55c 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -18,6 +18,7 @@ class ContractsManager { this.gasLimit = options.gasLimit; this.deployOnlyOnConfig = false; this.events = options.events; + this.compileError = false; self.events.on(constants.events.contractFilesChanged, (newContractFiles) => { self.contractFiles = newContractFiles; @@ -27,7 +28,7 @@ class ContractsManager { }); self.events.setCommandHandler('contracts:list', (cb) => { - cb(self.listContracts()); + cb(self.compileError, self.listContracts()); }); self.events.setCommandHandler("contracts:contract", (contractName, cb) => { @@ -36,8 +37,8 @@ class ContractsManager { self.events.setCommandHandler("contracts:build", (configOnly, cb) => { self.deployOnlyOnConfig = configOnly; // temporary, should refactor - self.build(() => { - cb(); + self.build((err) => { + cb(err); }); }); @@ -59,6 +60,7 @@ class ContractsManager { let self = this; async.waterfall([ function compileContracts(callback) { + self.events.emit("status", __("Compiling...")); if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) { // Only compile once for tests return callback(); @@ -69,6 +71,7 @@ class ContractsManager { }); }, function prepareContractsFromConfig(callback) { + self.events.emit("status", __("Building...")); let className, contract; for (className in self.contractsConfig.contracts) { contract = self.contractsConfig.contracts[className]; @@ -247,6 +250,8 @@ class ContractsManager { } ], function (err, _result) { if (err) { + self.compileError = true; + self.events.emit("status", __("Compile/Build error")); self.logger.error(__("Error Compiling/Building contracts: ") + err); } self.logger.trace("finished".underline); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 7f69e9e67..7f63a4d43 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -22,10 +22,15 @@ class DeployManager { deployAll(done) { let self = this; - this.logger.info(__("deploying contracts")); - this.events.emit("deploy:beforeAll"); - self.events.request('contracts:list', (contracts) => { + self.events.request('contracts:list', (err, contracts) => { + if (err) { + return done(err); + } + + self.logger.info(__("deploying contracts")); + self.events.emit("deploy:beforeAll"); + async.eachOfSeries(contracts, function (contract, key, callback) { contract._gasLimit = self.gasLimit; @@ -61,8 +66,8 @@ class DeployManager { async.waterfall([ function buildContracts(callback) { - self.events.request("contracts:build", self.deployOnlyOnConfig, () => { - callback(); + self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => { + callback(err); }); }, diff --git a/lib/index.js b/lib/index.js index bc5410df3..338ee7fc0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -121,11 +121,14 @@ class Embark { engine.startService("storage"); engine.startService("codeGenerator"); engine.startService("namingSystem"); - + engine.events.on('check:backOnline:Ethereum', function () { engine.logger.info(__('Ethereum node detected') + '..'); engine.config.reloadConfig(); - engine.events.request('deploy:contracts', function() { + engine.events.request('deploy:contracts', function(err) { + if (err) { + return; + } engine.logger.info(__('Deployment Done')); }); }); diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index db50770e1..544e1d26e 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -53,7 +53,7 @@ class Pipeline { next(); }, function writeContracts(next) { - self.events.request('contracts:list', (contracts) => { + self.events.request('contracts:list', (_err, contracts) => { // ensure the .embark/contracts directory exists (create if not exists) fs.mkdirp(fs.dappPath(".embark/contracts", ''), (err) => { if(err) return next(err); @@ -224,8 +224,8 @@ class Pipeline { }); }, function getContracts(next) { - self.events.request('contracts:list', (contracts) => { - next(null, contracts); + self.events.request('contracts:list', (err, contracts) => { + next(err, contracts); }); }, function writeContractsJSON(contracts, next) {