callback error from runCode and use that in onDeploy codes
This commit is contained in:
parent
d90d591fdc
commit
a62a74d162
|
@ -15,10 +15,16 @@ class CodeRunner {
|
|||
});
|
||||
|
||||
this.events.setCommandHandler('runcode:eval', (code, cb) => {
|
||||
let result = RunCode.doEval(code);
|
||||
if (cb) {
|
||||
cb(null, result);
|
||||
if (!cb) {
|
||||
cb = function() {};
|
||||
}
|
||||
try {
|
||||
let result = RunCode.doEval(code);
|
||||
cb(null, result);
|
||||
} catch (e) {
|
||||
cb(e);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,30 +52,30 @@ class SpecialConfigs {
|
|||
|
||||
async.mapLimit(afterDeployCmds, 1, (cmd, nextMapCb) => {
|
||||
self.replaceWithAddresses(cmd, nextMapCb);
|
||||
}, (err, result) => {
|
||||
}, (err, onDeployCode) => {
|
||||
if (err) {
|
||||
self.logger.trace(err);
|
||||
return cb(new Error("error running afterDeploy"));
|
||||
}
|
||||
let onDeployCode = result;
|
||||
|
||||
// TODO: convert to for to avoid repeated callback
|
||||
for(let cmd of onDeployCode) {
|
||||
self.logger.info("==== executing: " + cmd);
|
||||
try {
|
||||
self.events.request('runcode:eval', cmd);
|
||||
} 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 cb(new Error(e));
|
||||
}
|
||||
}
|
||||
cb();
|
||||
self.runOnDeployCode(onDeployCode, cb);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
runOnDeployCode(onDeployCode, callback) {
|
||||
const self = this;
|
||||
async.each(onDeployCode, (cmd, eachCb) => {
|
||||
self.logger.info("==== executing: " + cmd);
|
||||
self.events.request('runcode:eval', cmd, (err) => {
|
||||
if (err && err.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');
|
||||
}
|
||||
eachCb(err);
|
||||
});
|
||||
}, callback);
|
||||
}
|
||||
|
||||
registerOnDeployAction() {
|
||||
const self = this;
|
||||
|
||||
|
@ -92,25 +92,12 @@ class SpecialConfigs {
|
|||
|
||||
async.mapLimit(onDeployCmds, 1, (cmd, nextMapCb) => {
|
||||
self.replaceWithAddresses(cmd, nextMapCb);
|
||||
}, (err, result) => {
|
||||
}, (err, onDeployCode) => {
|
||||
if (err) {
|
||||
return cb(new Error("error running onDeploy for " + contract.className.cyan));
|
||||
}
|
||||
let onDeployCode = result;
|
||||
|
||||
// TODO: convert to for to avoid repeated callback
|
||||
for(let cmd of onDeployCode) {
|
||||
self.logger.info("==== executing: " + cmd);
|
||||
try {
|
||||
self.events.request('runcode:eval', cmd);
|
||||
} 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 cb(new Error(e));
|
||||
}
|
||||
}
|
||||
cb();
|
||||
self.runOnDeployCode(onDeployCode, cb);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue