on master help sign in
Better error throwing

For clearer stack traces

commita28394d47da0014c3bda8b683ba95322cabd272f authorFang <git@fang.io> dateTue 16 Jul 2019, 18:12 (7 years ago) parentccb7118
7 files changed+23−23
src/components/old/StatelessTransaction.js+1−1 src/lib/error.js+11−11 src/lib/keys.js+2−2 src/lib/need.js+6−6 src/store/network.js+1−1 src/store/wallet.js+1−1 src/views/SentTransaction.js+1−1
src/components/old/StatelessTransaction.js+1−1
@@ -185,7 +185,7 @@ class StatelessTransaction extends React.Component {
185185 const stx = state.stx.matchWith({
186186 Just: tx => tx.value,
187187 Nothing: () => {
188− throw BRIDGE_ERROR.MISSING_TXN;
188+ throw new Error(BRIDGE_ERROR.MISSING_TXN);
189189 },
190190 });
191191
src/lib/error.js+11−11
@@ -1,15 +1,15 @@
11const BRIDGE_ERROR = {
2− MISSING_WEB3: new Error('no web3 object found'),
3− MISSING_WALLET: new Error('no wallet found'),
4− MISSING_TXN: new Error('no transaction found'),
5− MISSING_CONTRACTS: new Error('no contracts found'),
6− MISSING_KEYSTORE: new Error('no keystore text found'),
7− MISSING_MNEMONIC: new Error('no authentication mnemonic found'),
8− MISSING_URBIT_WALLET: new Error('no urbit wallet found'),
9− MISSING_POINT: new Error('no point found'),
10− INVALID_ROUTE: new Error('invalid route'),
11− INVALID_NETWORK_TYPE: new Error('invalid network type'),
12− INVALID_WALLET_TYPE: new Error('invalid wallet type'),
2+ MISSING_WEB3: 'no web3 object found',
3+ MISSING_WALLET: 'no wallet found',
4+ MISSING_TXN: 'no transaction found',
5+ MISSING_CONTRACTS: 'no contracts found',
6+ MISSING_KEYSTORE: 'no keystore text found',
7+ MISSING_MNEMONIC: 'no authentication mnemonic found',
8+ MISSING_URBIT_WALLET: 'no urbit wallet found',
9+ MISSING_POINT: 'no point found',
10+ INVALID_ROUTE: 'invalid route',
11+ INVALID_NETWORK_TYPE: 'invalid network type',
12+ INVALID_WALLET_TYPE: 'invalid wallet type',
1313};
1414
1515const renderTxnError = (web3, msg) => {
src/lib/keys.js+2−2
@@ -89,7 +89,7 @@ const attemptNetworkSeedDerivation = async (next, args) => {
8989 const uwal = urbitWallet.matchWith({
9090 Just: uw => uw.value,
9191 Nothing: _ => {
92− throw BRIDGE_ERROR.MISSING_URBIT_WALLET;
92+ throw new Error(BRIDGE_ERROR.MISSING_URBIT_WALLET);
9393 },
9494 });
9595
@@ -100,7 +100,7 @@ const attemptNetworkSeedDerivation = async (next, args) => {
100100 const mnemonic = authMnemonic.matchWith({
101101 Just: mnem => mnem.value,
102102 Nothing: _ => {
103− throw BRIDGE_ERROR.MISSING_MNEMONIC;
103+ throw new Error(BRIDGE_ERROR.MISSING_MNEMONIC);
104104 },
105105 });
106106
src/lib/need.js+6−6
@@ -19,26 +19,26 @@ export const web3 = needBuilder(() => {
1919});
2020
2121export const contracts = needBuilder(() => {
22− throw new Error(BRIDGE_ERROR.MISSING_CONTRACTS.message);
22+ throw new Error(BRIDGE_ERROR.MISSING_CONTRACTS);
2323});
2424
2525export const wallet = needBuilder(() => {
26− throw new Error(BRIDGE_ERROR.MISSING_WALLET.message);
26+ throw new Error(BRIDGE_ERROR.MISSING_WALLET);
2727});
2828
2929export const addressFromWallet = obj => wallet(obj).address;
3030
3131export const point = needBuilder(() => {
32− throw new Error(BRIDGE_ERROR.MISSING_POINT.message);
32+ throw new Error(BRIDGE_ERROR.MISSING_POINT);
3333});
3434
3535export const pointCache = needBuilder(() => {
36− throw new Error(BRIDGE_ERROR.MISSING_POINT.message);
36+ throw new Error(BRIDGE_ERROR.MISSING_POINT);
3737});
3838
3939export const fromPointCache = (cache, point) => {
4040 if (!(point in cache)) {
41− throw new Error(BRIDGE_ERROR.MISSING_POINT.message);
41+ throw new Error(BRIDGE_ERROR.MISSING_POINT);
4242 }
4343
4444 return cache[point];
@@ -49,7 +49,7 @@ export const keystore = obj => {
4949 return ks.value.matchWith({
5050 Ok: result => result.value,
5151 Error: _ => {
52− throw BRIDGE_ERROR.MISSING_KEYSTORE;
52+ throw new Error(BRIDGE_ERROR.MISSING_KEYSTORE);
5353 },
5454 });
5555};
src/store/network.js+1−1
@@ -20,7 +20,7 @@ function _useNetwork(initialNetworkType = null) {
2020
2121 const setNetworkType = networkType => {
2222 if (!includes(NETWORK_TYPES, networkType)) {
23− throw BRIDGE_ERROR.INVALID_NETWORK_TYPE;
23+ throw new Error(BRIDGE_ERROR.INVALID_NETWORK_TYPE);
2424 }
2525 _setNetworkType(networkType);
2626 };
src/store/wallet.js+1−1
@@ -44,7 +44,7 @@ function _useWallet(initialWallet = Nothing(), initialMnemonic = Nothing()) {
4444 const setWalletType = useCallback(
4545 walletType => {
4646 if (!includes(WALLET_TYPES, walletType)) {
47− throw BRIDGE_ERROR.INVALID_WALLET_TYPE;
47+ throw new Error(BRIDGE_ERROR.INVALID_WALLET_TYPE);
4848 }
4949
5050 _setWalletType(walletType);
src/views/SentTransaction.js+1−1
@@ -125,7 +125,7 @@ function SentTransaction(props) {
125125
126126 const result = txnCursor.matchWith({
127127 Nothing: _ => {
128− throw BRIDGE_ERROR.MISSING_TXN;
128+ throw new Error(BRIDGE_ERROR.MISSING_TXN);
129129 },
130130 Just: res => res.value,
131131 });