From 1491028665afb2e573c683b920017a19a1c4f7e9 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 12 Jul 2019 10:51:26 -0400 Subject: [PATCH] use callbacks instead of exiting --- dapps/templates/demo/test/simple_storage_spec.js | 4 ++-- packages/embark-blockchain-connector/src/index.js | 11 +++++++++-- packages/embark-blockchain-connector/src/provider.js | 5 +++-- packages/embark-blockchain-process/src/blockchain.js | 3 ++- packages/embark-blockchain-process/src/simulator.js | 3 ++- packages/embark-test-runner/src/test.js | 5 +++-- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dapps/templates/demo/test/simple_storage_spec.js b/dapps/templates/demo/test/simple_storage_spec.js index aa09607d5..e8a845653 100644 --- a/dapps/templates/demo/test/simple_storage_spec.js +++ b/dapps/templates/demo/test/simple_storage_spec.js @@ -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 () { diff --git a/packages/embark-blockchain-connector/src/index.js b/packages/embark-blockchain-connector/src/index.js index 36653924f..025bc8dcb 100644 --- a/packages/embark-blockchain-connector/src/index.js +++ b/packages/embark-blockchain-connector/src/index.js @@ -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); diff --git a/packages/embark-blockchain-connector/src/provider.js b/packages/embark-blockchain-connector/src/provider.js index 90e0951a5..5f0ff2dd7 100644 --- a/packages/embark-blockchain-connector/src/provider.js +++ b/packages/embark-blockchain-connector/src/provider.js @@ -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) { diff --git a/packages/embark-blockchain-process/src/blockchain.js b/packages/embark-blockchain-process/src/blockchain.js index 7dc9a3fa7..080db39a3 100644 --- a/packages/embark-blockchain-process/src/blockchain.js +++ b/packages/embark-blockchain-process/src/blockchain.js @@ -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); } diff --git a/packages/embark-blockchain-process/src/simulator.js b/packages/embark-blockchain-process/src/simulator.js index 60fc80e4b..8f5c22868 100644 --- a/packages/embark-blockchain-process/src/simulator.js +++ b/packages/embark-blockchain-process/src/simulator.js @@ -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) => { diff --git a/packages/embark-test-runner/src/test.js b/packages/embark-test-runner/src/test.js index 5f55a333d..e7ddde57f 100644 --- a/packages/embark-test-runner/src/test.js +++ b/packages/embark-test-runner/src/test.js @@ -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); }