use callbacks instead of exiting

This commit is contained in:
Jonathan Rainville 2019-07-12 10:51:26 -04:00
parent 6afa07f111
commit 1491028665
6 changed files with 21 additions and 10 deletions

View File

@ -1,4 +1,4 @@
/*global contract, config, it, assert*/
/*global contract, config, it, assert, web3*/
const SimpleStorage = require('Embark/contracts/SimpleStorage');
let accounts;
@ -17,7 +17,7 @@ config({
}
}
}, (_err, web3_accounts) => {
accounts = web3_accounts
accounts = web3_accounts;
});
contract("SimpleStorage", function () {

View File

@ -64,7 +64,11 @@ class BlockchainConnector {
embark.registerActionForEvent("contracts:deploy:afterAll", this.subscribeToContractEvents.bind(this));
if (!this.web3) {
this.initWeb3();
this.initWeb3(err => {
if (err) {
this.logger.error(__('Error initiating Web3 provider'), err.message || err);
}
});
} else {
this.isWeb3Ready = true;
}
@ -177,7 +181,10 @@ class BlockchainConnector {
if (err) {
return self.logger.error(err);
}
self.provider.startWeb3Provider(async () => {
self.provider.startWeb3Provider(async (err) => {
if (err) {
return cb(err);
}
try {
const blockNumber = await self.web3.eth.getBlockNumber();
await self.web3.eth.getBlock(blockNumber);

View File

@ -17,6 +17,7 @@ class Provider {
this.isDev = options.isDev;
this.events = options.events;
this.nonceCache = {};
this.accounts = [];
this.events.setCommandHandler("blockchain:provider:contract:accounts:get", cb => {
const accounts = this.accounts.map(a => a.address || a);
@ -80,8 +81,8 @@ class Provider {
accounts = accounts.concat(self.blockchainAccounts);
self.accounts = AccountParser.parseAccountsConfig(self.accountsConfig, self.web3, dappPath(), self.logger, accounts);
} catch (_e) {
process.exit(1);
} catch (e) {
return callback(e);
}
if (!self.accounts.length) {

View File

@ -166,7 +166,8 @@ Blockchain.prototype.setupProxy = async function () {
let addresses;
try {
addresses = AccountParser.parseAccountsConfig(this.userConfig.accounts, false, dappPath(), this.logger);
} catch (_e) {
} catch (e) {
this.logger.error(e.message);
process.exit(1);
}

View File

@ -45,7 +45,8 @@ export class Simulator {
let parsedAccounts;
try {
parsedAccounts = AccountParser.parseAccountsConfig(simulatorAccounts, web3, dappPath(), this.logger);
} catch (_e) {
} catch (e) {
this.logger.error(e.message);
process.exit(1);
}
parsedAccounts.forEach((account) => {

View File

@ -159,8 +159,8 @@ class Test {
if (accounts) {
try {
self.simOptions.accounts = AccountParser.parseAccountsConfig(accounts, web3, this.dappPath);
} catch (_e) {
process.exit(1);
} catch (e) {
return callback(e);
}
} else {
self.simOptions.accounts = null;
@ -255,6 +255,7 @@ class Test {
}
], (err, accounts) => {
if (err) {
self.logger.error(err.message || err);
// TODO Do not exit in case of not a normal run (eg after a change)
if (!self.options.inProcess) process.exit(1);
}