fix/improve error handling

This commit is contained in:
Iuri Matias 2017-12-27 13:07:13 -05:00
parent 750eace6ce
commit aad78cc130
2 changed files with 17 additions and 2 deletions

View File

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

View File

@ -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<output.errors; i++) {
for (let i=0; i<output.errors.length; i++) {
if (output.errors[i].indexOf('Warning:') >= 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) {