From aad78cc130db39024e5da447524fad4b38ddb8fc Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 27 Dec 2017 13:07:13 -0500 Subject: [PATCH] fix/improve error handling --- lib/contracts/deploy_manager.js | 10 +++++++++- lib/modules/solidity/index.js | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 3f9990c6b..b59673381 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -117,9 +117,17 @@ class DeployManager { return callback(new Error("error running afterDeploy")); } + // TODO: convert to for to avoid repeated callback onDeployCode.forEach((cmd) => { self.logger.info("executing: " + cmd); - RunCode.doEval(cmd, web3); + try { + RunCode.doEval(cmd, web3); + } catch(e) { + if (e.message.indexOf("invalid opcode") >= 0) { + self.logger.error('the transaction was rejected; this usually happens due to a throw or a require, it can also happen due to an invalid operation'); + } + return callback(new Error(e)); + } }); callback(null, contractsManager); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 2087268bd..0270214ae 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -51,8 +51,11 @@ class Solidity { self.logger.info("compiling contracts..."); solcW.compile({sources: input}, 1, function (output) { if (output.errors) { - for (let i=0; i= 0) { + //return callback(new Error("Solidity errors: " + output.errors).message); + } + if (output.errors[i].indexOf('Error:') >= 0) { return callback(new Error("Solidity errors: " + output.errors).message); } } @@ -64,6 +67,10 @@ class Solidity { function createCompiledObject(output, callback) { let json = output.contracts; + if (Object.keys(output.contracts).length === 0 && output.sourceList.length > 0) { + return callback(new Error("error compiling. There are sources available but no code could be compiled, likely due to fatal errors in the solidity code").message); + } + let compiled_object = {}; for (let contractName in json) {