Skip to content

Commit

Permalink
Merge pull request #1580 from EdgeApp/william/error-insanity
Browse files Browse the repository at this point in the history
Audit every `catch` statement in the codebase
  • Loading branch information
swansontec authored Sep 24, 2019
2 parents 6cf6828 + 6e9f5d9 commit e94b4f3
Show file tree
Hide file tree
Showing 27 changed files with 107 additions and 175 deletions.
7 changes: 4 additions & 3 deletions src/actions/CryptoExchangeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { Actions } from 'react-native-router-flux'
import { sprintf } from 'sprintf-js'

import { SwapVerifyShapeshiftModal } from '../components/modals/SwapVerifyShapeshiftModal.js'
import { Airship } from '../components/services/AirshipInstance.js'
import { Airship, showError } from '../components/services/AirshipInstance.js'
import * as Constants from '../constants/indexConstants'
import { intl } from '../locales/intl'
import s from '../locales/strings.js'
Expand Down Expand Up @@ -108,8 +108,8 @@ export const exchangeMax = () => async (dispatch: Dispatch, getState: GetState)
spendTargets: [{ publicAddress }]
}
primaryNativeAmount = await wallet.getMaxSpendable(edgeSpendInfo)
} catch (e) {
console.log(e.name, e.message)
} catch (error) {
showError(error)
}
dispatch({ type: 'SET_FROM_WALLET_MAX', data: primaryNativeAmount })
}
Expand Down Expand Up @@ -322,6 +322,7 @@ export const shiftCryptoCurrency = (swapInfo: GuiSwapInfo) => async (dispatch: D
}, 1)
global.firebase && global.firebase.analytics().logEvent(`Exchange_Shift_Success`)
} catch (error) {
console.log(error)
global.firebase && global.firebase.analytics().logEvent(`Exchange_Shift_Failed`)
dispatch({ type: 'DONE_SHIFT_TRANSACTION' })
setTimeout(() => {
Expand Down
26 changes: 8 additions & 18 deletions src/actions/OtpActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,20 @@ import type { Dispatch, GetState } from '../types/reduxTypes.js'
export const enableOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.enableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: true, otpKey: account.otpKey }))
} catch (error) {
console.log(error)
}
await account.enableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: true, otpKey: account.otpKey }))
}

export const disableOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.disableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: false, otpKey: null, otpResetPending: false }))
} catch (error) {
console.log(error)
}
await account.disableOtp()
dispatch(SETTINGS_ACTIONS.updateOtpInfo({ enabled: false, otpKey: null, otpResetPending: false }))
}

export const keepOtp = () => async (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
try {
await account.cancelOtpReset()
dispatch({ type: 'DISABLE_OTP_RESET' })
} catch (error) {
throw new Error(error)
}
await account.cancelOtpReset()
dispatch({ type: 'DISABLE_OTP_RESET' })
}
11 changes: 2 additions & 9 deletions src/actions/RequestActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,8 @@ export const saveReceiveAddress = (receiveAddress: Object) => (dispatch: Dispatc
const selectedCurrencyCode = UI_SELECTORS.getSelectedCurrencyCode(state)
const wallet = CORE_SELECTORS.getWallet(state, selectedWalletId)

const onSuccess = () => {
dispatch(updateReceiveAddress(selectedWalletId, selectedCurrencyCode))
}
const onError = e => {
console.log(e)
}

wallet
.saveReceiveAddress(receiveAddress)
.then(onSuccess)
.catch(onError)
.then(() => dispatch(updateReceiveAddress(selectedWalletId, selectedCurrencyCode)))
.catch(showError)
}
6 changes: 1 addition & 5 deletions src/actions/ResyncWalletModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export const showResyncWalletModal = (walletId: string) => async (dispatch: Disp
const resolveValue = await launchModal(modal)

if (resolveValue) {
try {
wallet.resyncBlockchain()
} catch (e) {
throw new Error(e)
}
await wallet.resyncBlockchain()
}
}
9 changes: 3 additions & 6 deletions src/actions/ScanActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ const doRequestAddress = (dispatch: Dispatch, edgeWallet: EdgeCurrencyWallet, gu
const addr = guiWallet.receiveAddress.publicAddress
const url = decodeURIComponent(requestAddress.callbackUrl)
const finalUrl = url + '?address=' + encodeURIComponent(addr)
try {
Linking.openURL(finalUrl)
} catch (e) {
throw new Error(e)
}
Linking.openURL(finalUrl)
}
})
.catch(e => {
Expand Down Expand Up @@ -368,6 +364,7 @@ export const checkAndShowGetCryptoModal = () => async (dispatch: Dispatch, getSt
Actions[EXCHANGE_SCENE]()
}
} catch (e) {
console.log('error generating encodedURI: ', e)
// Don't bother the user with this error, but log it quietly:
console.log(e)
}
}
3 changes: 2 additions & 1 deletion src/actions/SendConfirmationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Actions } from 'react-native-router-flux'
import { sprintf } from 'sprintf-js'

import { launchModal } from '../components/common/ModalProvider.js'
import { showError } from '../components/services/AirshipInstance.js'
import { EXCLAMATION, FEE_ALERT_THRESHOLD, MATERIAL_COMMUNITY, SEND_CONFIRMATION, TRANSACTION_DETAILS } from '../constants/indexConstants'
import { getSpecialCurrencyInfo, getSymbolFromCurrency } from '../constants/WalletAndCurrencyConstants.js'
import s from '../locales/strings.js'
Expand Down Expand Up @@ -164,7 +165,7 @@ export const updateMaxSpend = () => (dispatch: Dispatch, getState: GetState) =>

dispatch(updateAmount(nativeAmount, exchangeAmount, fiatPerCrypto.toString(), true))
})
.catch(e => console.log(e))
.catch(showError)
}

export const signBroadcastAndSave = () => async (dispatch: Dispatch, getState: GetState) => {
Expand Down
43 changes: 15 additions & 28 deletions src/actions/SettingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export const setPINModeRequest = (pinMode: boolean) => (dispatch: Dispatch, getS
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setPINModeRequest(account, pinMode)
.then(() => dispatch(SETTINGS_ACTIONS.setPINMode(pinMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setAutoLogoutTimeInMinutesRequest = (autoLogoutTimeInMinutes: number) => {
Expand All @@ -55,9 +53,7 @@ export const setAutoLogoutTimeInSecondsRequest = (autoLogoutTimeInSeconds: numbe
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setAutoLogoutTimeInSecondsRequest(account, autoLogoutTimeInSeconds)
.then(() => dispatch(SETTINGS_ACTIONS.setAutoLogoutTimeInSeconds(autoLogoutTimeInSeconds)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setDefaultFiatRequest = (defaultFiat: string) => (dispatch: Dispatch, getState: GetState) => {
Expand Down Expand Up @@ -96,27 +92,23 @@ export const setDefaultFiatRequest = (defaultFiat: string) => (dispatch: Dispatc
dispatch(newSpendingLimits(nextSpendingLimits))
dispatch(updateExchangeRates())
})
.catch(e => console.log(e))
.catch(showError)
}

export const setMerchantModeRequest = (merchantMode: boolean) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setMerchantModeRequest(account, merchantMode)
.then(() => dispatch(SETTINGS_ACTIONS.setMerchantMode(merchantMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const setBluetoothModeRequest = (bluetoothMode: boolean) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
ACCOUNT_SETTINGS.setBluetoothModeRequest(account, bluetoothMode)
.then(() => dispatch(SETTINGS_ACTIONS.setBluetoothMode(bluetoothMode)))
.catch(error => {
console.error(error)
})
.catch(showError)
}

export const checkCurrentPassword = (arg: string) => async (dispatch: Dispatch, getState: GetState) => {
Expand All @@ -139,12 +131,10 @@ export const lockSettings = () => async (dispatch: Dispatch) => {
export const setDenominationKeyRequest = (currencyCode: string, denominationKey: string) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const account = CORE_SELECTORS.getAccount(state)
const onSuccess = () => dispatch(SETTINGS_ACTIONS.setDenominationKey(currencyCode, denominationKey))
const onError = e => console.log(e)

return ACCOUNT_SETTINGS.setDenominationKeyRequest(account, currencyCode, denominationKey)
.then(onSuccess)
.catch(onError)
.then(() => dispatch(SETTINGS_ACTIONS.setDenominationKey(currencyCode, denominationKey)))
.catch(showError)
}

// touch id interaction
Expand Down Expand Up @@ -205,9 +195,8 @@ export const enableCustomNodes = (currencyCode: string) => async (dispatch: Disp
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, disableFetchingServers: true })
} catch (e) {
console.log(e)
throw new Error(e)
} catch (error) {
showError(error)
}
}

Expand All @@ -218,9 +207,8 @@ export const disableCustomNodes = (currencyCode: string) => async (dispatch: Dis
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, disableFetchingServers: false })
} catch (e) {
console.log(e)
throw new Error(e)
} catch (error) {
showError(error)
}
}

Expand All @@ -231,9 +219,8 @@ export const saveCustomNodesList = (currencyCode: string, nodesList: Array<strin
const currencyPlugin = account.currencyConfig[currencyPluginName]
try {
await currencyPlugin.changeUserSettings({ ...currencyPlugin.userSettings, electrumServers: nodesList })
} catch (e) {
console.log(e)
throw new Error('Unable to save plugin setting')
} catch (error) {
showError(error)
}
}

Expand Down Expand Up @@ -281,8 +268,8 @@ export const showUnlockSettingsModal = () => async (dispatch: Dispatch, getState
if (resolveValue) {
dispatch(SETTINGS_ACTIONS.setSettingsLock(false))
}
} catch (e) {
throw new Error('Unable to unlock settings')
} catch (error) {
showError(error)
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/actions/SplitWalletModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createYesNoModal } from 'edge-components'
import React from 'react'

import { launchModal } from '../components/common/ModalProvider.js'
import { showError } from '../components/services/AirshipInstance.js'
import { SPLIT } from '../constants/indexConstants.js'
import s from '../locales/strings.js'
import { getAccount, getWallet, getWalletName } from '../modules/Core/selectors.js'
Expand Down Expand Up @@ -47,8 +48,8 @@ export const showSplitWalletModal = (walletId: string) => async (dispatch: Dispa
const splitType = getSplitType(wallet.currencyInfo.currencyCode)
await account.splitWalletInfo(walletId, splitType)
dispatch(refreshWallet(walletId))
} catch (e) {
throw new Error(e)
} catch (error) {
showError(error)
}
}
}
17 changes: 7 additions & 10 deletions src/actions/TransactionDetailsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import type { EdgeMetadata, EdgeTransaction } from 'edge-core-js'
import { Actions } from 'react-native-router-flux'

import { showError } from '../components/services/AirshipInstance.js'
import * as ACCOUNT_SETTINGS from '../modules/Core/Account/settings.js'
import type { Dispatch, GetState, State } from '../types/reduxTypes.js'
import { refreshTransactionsRequest } from './TransactionListActions.js'
Expand All @@ -15,15 +16,13 @@ export const setSubcategories = (subcategories: Array<string>) => ({
export const setTransactionDetails = (transaction: EdgeTransaction, edgeMetadata: EdgeMetadata) => (dispatch: Dispatch, getState: GetState) => {
const state = getState()
const wallet = getSelectedWallet(state)
const onSuccess = () => {
dispatch(refreshTransactionsRequest(wallet.id, [transaction]))
Actions.pop()
}
const onError = () => {}
wallet
.saveTxMetadata(transaction.txid, transaction.currencyCode, edgeMetadata)
.then(onSuccess)
.catch(onError)
.then(() => {
dispatch(refreshTransactionsRequest(wallet.id, [transaction]))
Actions.pop()
})
.catch(showError)
}

export const getSubcategories = () => (dispatch: Dispatch, getState: GetState) => {
Expand All @@ -42,9 +41,7 @@ export const setNewSubcategory = (newSubcategory: string) => (dispatch: Dispatch
.then(() => {
dispatch(setSubcategories(newSubcategories.sort()))
})
.catch(e => {
console.error(e)
})
.catch(showError)
}

export const getSelectedWallet = (state: State) => {
Expand Down
5 changes: 3 additions & 2 deletions src/actions/TransactionListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { EdgeTransaction } from 'edge-core-js'
import _ from 'lodash'

import { showTransactionDropdown } from '../components/navigation/TransactionDropdown.js'
import { showError } from '../components/services/AirshipInstance.js'
import * as CORE_SELECTORS from '../modules/Core/selectors.js'
import * as UI_SELECTORS from '../modules/UI/selectors.js'
import type { Dispatch, GetState, State } from '../types/reduxTypes.js'
Expand Down Expand Up @@ -135,8 +136,8 @@ const getAndMergeTransactions = async (state: State, dispatch: Dispatch, walletI
currentEndIndex: lastUnfilteredIndex
})
)
} catch (e) {
console.log('Issue with getTransactions: ', e.message)
} catch (error) {
showError(error)
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/actions/WalletActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ export const selectWallet = (walletId: string, currencyCode: string, from?: stri
.then(receiveAddress => {
dispatch({ type: 'NEW_RECEIVE_ADDRESS', data: { receiveAddress } })
})
.catch(e => {
console.log('error on getting wallet receive address')
})
.catch(showError)
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/actions/WalletListActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import { showError } from '../components/services/AirshipInstance.js'
import * as ACCOUNT_SETTINGS from '../modules/Core/Account/settings.js'
import * as CORE_SELECTORS from '../modules/Core/selectors.js'
import { setAccountBalanceVisibility, updateWalletFiatBalanceVisibility } from '../modules/Settings/SettingsActions.js'
Expand All @@ -14,7 +15,7 @@ export const updateActiveWalletsOrder = (activeWalletIds: Array<string>) => (dis
return keyStates
}, {})

return account.changeWalletStates(newKeyStates).catch(error => console.log(error))
return account.changeWalletStates(newKeyStates).catch(showError)
}

export const toggleAccountBalanceVisibility = () => (dispatch: Dispatch, getState: GetState) => {
Expand All @@ -25,7 +26,7 @@ export const toggleAccountBalanceVisibility = () => (dispatch: Dispatch, getStat
.then(() => {
dispatch(setAccountBalanceVisibility(!currentAccountBalanceVisibility))
})
.catch(error => console.error(error))
.catch(showError)
}

export const toggleWalletFiatBalanceVisibility = () => (dispatch: Dispatch, getState: GetState) => {
Expand All @@ -36,7 +37,7 @@ export const toggleWalletFiatBalanceVisibility = () => (dispatch: Dispatch, getS
.then(() => {
dispatch(updateWalletFiatBalanceVisibility(!currentWalletFiatBalanceVisibility))
})
.catch(error => console.error(error))
.catch(showError)
}

export const updateArchivedWalletsOrder = (archivedWalletIds: Array<string>) => (dispatch: Dispatch, getState: GetState) => {
Expand Down
Loading

0 comments on commit e94b4f3

Please sign in to comment.