Skip to content

Commit

Permalink
Move some errors to analytics instead of sentry (#2529)
Browse files Browse the repository at this point in the history
* Move some errors to analytics instead of sentry

* Add swaps errors

* Change to log just as 1 error

* Fix typos

* Log can't reach branch servers as analytics

* Browser: Failed to resolve ENS name for chainId - log as analytics

* Update tests

Co-authored-by: Pedro Pablo Aste Kompen <wachunei@gmail.com>
  • Loading branch information
andrepimenta and wachunei authored Apr 30, 2021
1 parent 291dc6f commit 68c9d6c
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 151 deletions.
7 changes: 6 additions & 1 deletion app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Engine from '../../../core/Engine';
import Logger from '../../../util/Logger';
import Branch from 'react-native-branch';
import AppConstants from '../../../core/AppConstants';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

/**
* Stack navigator responsible for the onboarding process
Expand Down Expand Up @@ -186,7 +187,11 @@ class App extends PureComponent {

handleDeeplinks = async ({ error, params, uri }) => {
if (error) {
Logger.error(error, 'Deeplink: Error from Branch');
if (error === 'Trouble reaching the Branch servers, please try again shortly.') {
trackErrorAsAnalytics('Branch: Trouble reaching servers', error);
} else {
Logger.error(error, 'Deeplink: Error from Branch');
}
}
const deeplink = params['+non_branch_link'] || uri || null;
try {
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/AssetOverview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class AssetOverview extends PureComponent {
try {
await SwapsController.fetchTokenWithCache();
} catch (error) {
Logger.error(error, 'Swaps: error while fetching tokens with catche in AssetOverview');
Logger.error(error, 'Swaps: error while fetching tokens with cache in AssetOverview');
}
};

Expand Down
12 changes: 11 additions & 1 deletion app/components/UI/ComponentErrorBoundary/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import Logger from '../../../util/Logger';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

class ComponentErrorBoundary extends React.Component {
state = { error: null };
Expand All @@ -17,7 +18,11 @@ class ComponentErrorBoundary extends React.Component {
/**
* Function to be called when there is an error
*/
onError: PropTypes.func
onError: PropTypes.func,
/**
* Will not track as an error, but still log to analytics
*/
dontTrackAsError: PropTypes.bool
};

static getDerivedStateFromError(error) {
Expand All @@ -28,6 +33,11 @@ class ComponentErrorBoundary extends React.Component {
// eslint-disable-next-line no-unused-expressions
this.props.onError?.();

const { componentLabel, dontTrackAsError } = this.props;

if (dontTrackAsError) {
return trackErrorAsAnalytics(`Component Error Boundary: ${componentLabel}`, error?.message);
}
Logger.error(error, { View: this.props.componentLabel, ...errorInfo });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ function TransactionNotification(props) {
accounts,
currentNotification,
isInBrowserView,
navigation,
notificationAnimated,
onClose,
transactions,
Expand Down Expand Up @@ -254,7 +253,6 @@ function TransactionNotification(props) {
<TransactionDetails
transactionObject={tx}
transactionDetails={transactionDetails}
navigation={navigation}
close={onCloseDetails}
showSpeedUpModal={onSpeedUpPress}
showCancelModal={onCancelPress}
Expand Down Expand Up @@ -324,10 +322,6 @@ TransactionNotification.propTypes = {
*/
accounts: PropTypes.object,
/**
/* navigation object required to push new views
*/
navigation: PropTypes.object,
/**
* An array that represents the user transactions on chain
*/
transactions: PropTypes.array,
Expand Down
5 changes: 3 additions & 2 deletions app/components/UI/Swaps/QuotesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import InfoModal from './components/InfoModal';
import useModalHandler from '../../Base/hooks/useModalHandler';
import useBalance from './utils/useBalance';
import useGasPrice from './utils/useGasPrice';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';
import { decodeApproveData, getTicker } from '../../../util/transactions';
import Logger from '../../../util/Logger';

const POLLING_INTERVAL = AppConstants.SWAPS.POLLING_INTERVAL;
const EDIT_MODE_GAS = 'EDIT_MODE_GAS';
Expand Down Expand Up @@ -778,7 +778,6 @@ function SwapsQuotesView({
slippage,
custom_slippage: slippage !== AppConstants.SWAPS.DEFAULT_SLIPPAGE
};
Logger.error(error?.description, `Swaps: ${error?.key}`);
if (error?.key === swapsUtils.SwapsError.QUOTES_EXPIRED_ERROR) {
InteractionManager.runAfterInteractions(() => {
const parameters = {
Expand All @@ -794,6 +793,8 @@ function SwapsQuotesView({
Analytics.trackEventWithParameters(ANALYTICS_EVENT_OPTS.NO_QUOTES_AVAILABLE, {});
Analytics.trackEventWithParameters(ANALYTICS_EVENT_OPTS.NO_QUOTES_AVAILABLE, parameters, true);
});
} else {
trackErrorAsAnalytics(`Swaps: ${error?.key}`, error?.description);
}
},
[sourceToken, sourceAmount, destinationToken, hasEnoughTokenBalance, slippage]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,125 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`TransactionDetails should render correctly 1`] = `
<DetailsModalBody>
<DetailsModalSection
borderBottom={true}
>
<DetailsModalColumn>
<DetailsModalSectionTitle>
Status
</DetailsModalSectionTitle>
<StatusText
context="transaction"
status="confirmed"
/>
</DetailsModalColumn>
<DetailsModalColumn
end={true}
>
<DetailsModalSectionTitle>
Date
</DetailsModalSectionTitle>
<Text
black={false}
blue={false}
bold={false}
centered={false}
disclaimer={false}
green={false}
link={false}
modal={false}
primary={true}
red={false}
reset={false}
right={false}
small={true}
strikethrough={false}
underline={false}
upper={false}
>
[missing "en.date.months.NaN" translation] NaN at NaN:NaNam
</Text>
</DetailsModalColumn>
</DetailsModalSection>
<DetailsModalSection
borderBottom={false}
>
<DetailsModalColumn>
<DetailsModalSectionTitle>
From
</DetailsModalSectionTitle>
<Text
black={false}
blue={false}
bold={false}
centered={false}
disclaimer={false}
green={false}
link={false}
modal={false}
primary={true}
red={false}
reset={false}
right={false}
small={true}
strikethrough={false}
underline={false}
upper={false}
>
<Connect(EthereumAddress)
address="0x0"
type="short"
/>
</Text>
</DetailsModalColumn>
<DetailsModalColumn
end={true}
>
<DetailsModalSectionTitle>
To
</DetailsModalSectionTitle>
<Text
black={false}
blue={false}
bold={false}
centered={false}
disclaimer={false}
green={false}
link={false}
modal={false}
primary={true}
red={false}
reset={false}
right={false}
small={true}
strikethrough={false}
underline={false}
upper={false}
>
<Connect(EthereumAddress)
address="0x1"
type="short"
/>
</Text>
</DetailsModalColumn>
</DetailsModalSection>
<View
style={
Array [
Object {
"marginVertical": 8,
},
Object {
"marginBottom": 24,
"marginTop": 12,
},
]
<withNavigation(TransactionDetails)
dispatch={[Function]}
frequentRpcList={Array []}
network={
Object {
"provider": Object {
"rpcTarget": "",
"type": "rpc",
},
}
>
<TransactionSummary
gasEstimationReady={true}
/>
</View>
</DetailsModalBody>
}
transactionDetails={
Object {
"renderFrom": "0x0",
"renderGas": "21000",
"renderGasPrice": "2",
"renderTo": "0x1",
"renderTotalValue": "2 TKN / 0.001 ETH",
"renderTotalValueFiat": "",
"renderValue": "2 TKN",
"transactionHash": "0x2",
}
}
transactionObject={
Object {
"networkID": "1",
"status": "confirmed",
"transaction": Object {
"nonce": "",
},
}
}
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import StatusText from '../../../Base/StatusText';
import Text from '../../../Base/Text';
import DetailsModal from '../../../Base/DetailsModal';
import { RPC } from '../../../../constants/network';
import { withNavigation } from 'react-navigation';

const styles = StyleSheet.create({
viewOnEtherscan: {
Expand Down Expand Up @@ -262,4 +263,4 @@ const mapStateToProps = state => ({
chainId: state.engine.backgroundState.NetworkController.provider.chainId,
frequentRpcList: state.engine.backgroundState.PreferencesController.frequentRpcList
});
export default connect(mapStateToProps)(TransactionDetails);
export default connect(mapStateToProps)(withNavigation(TransactionDetails));
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ describe('TransactionDetails', () => {
context: { store: mockStore(initialState) }
}
);
expect(wrapper.dive()).toMatchSnapshot();
expect(wrapper).toMatchSnapshot();
});
});
5 changes: 0 additions & 5 deletions app/components/UI/TransactionElement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ const transactionIconReceivedFailed = require('../../../images/transaction-icons
class TransactionElement extends PureComponent {
static propTypes = {
assetSymbol: PropTypes.string,
/**
/* navigation object required to push new views
*/
navigation: PropTypes.object,
/**
* Asset object (in this case ERC721 token)
*/
Expand Down Expand Up @@ -347,7 +343,6 @@ class TransactionElement extends PureComponent {
<TransactionDetails
transactionObject={tx}
transactionDetails={transactionDetails}
navigation={this.props.navigation}
close={this.onCloseDetailsModal}
/>
</DetailsModal>
Expand Down
10 changes: 8 additions & 2 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { RPC } from '../../../constants/network';
import RPCMethods from '../../../core/RPCMethods';
import AddCustomNetwork from '../../UI/AddCustomNetwork';
import SwitchCustomNetwork from '../../UI/SwitchCustomNetwork';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const { HOMEPAGE_URL, USER_AGENT, NOTIFICATION_NAMES } = AppConstants;
const HOMEPAGE_HOST = 'home.metamask.io';
Expand Down Expand Up @@ -913,8 +914,13 @@ export const BrowserTab = props => {
ensIgnoreList.push(hostname);
return { url: fullUrl, reload: true };
}
Logger.error(err, 'Failed to resolve ENS name');
Alert.alert(strings('browser.error'), strings('browser.failed_to_resolve_ens_name'));
if (err?.message?.startsWith('EnsIpfsResolver - no known ens-ipfs registry for chainId')) {
trackErrorAsAnalytics('Browser: Failed to resolve ENS name for chainId', err?.message);
} else {
Logger.error(err, 'Failed to resolve ENS name');
}

Alert.alert(strings('browser.failed_to_resolve_ens_name'), err.message);
goBack();
}
},
Expand Down
7 changes: 6 additions & 1 deletion app/components/Views/LockScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SecureKeychain from '../../../core/SecureKeychain';
import { baseStyles } from '../../../styles/common';
import Logger from '../../../util/Logger';
import { NavigationActions } from 'react-navigation';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const LOGO_SIZE = 175;
const styles = StyleSheet.create({
Expand Down Expand Up @@ -129,7 +130,11 @@ class LockScreen extends PureComponent {
if (this.unlockAttempts <= 3) {
this.unlockKeychain();
} else {
Logger.error(error, { message: 'Lockscreen:maxAttemptsReached', attemptNumber: this.unlockAttempts });
trackErrorAsAnalytics(
'Lockscreen: Max Attempts Reached',
error?.message,
`Unlock attempts: ${this.unlockAttempts}`
);
this.props.navigation.navigate('Login');
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/components/Views/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { passwordRequirementsMet } from '../../../util/password';
import ErrorBoundary from '../ErrorBoundary';
import WarningExistingUserModal from '../../UI/WarningExistingUserModal';
import Icon from 'react-native-vector-icons/FontAwesome';
import { trackErrorAsAnalytics } from '../../../util/analyticsV2';

const isTextDelete = text => String(text).toLowerCase() === 'delete';
const deviceHeight = Device.getDeviceHeight();
Expand Down Expand Up @@ -319,6 +320,10 @@ class Login extends PureComponent {
error.toLowerCase() === WRONG_PASSWORD_ERROR_ANDROID.toLowerCase()
) {
this.setState({ loading: false, error: strings('login.invalid_password') });

trackErrorAsAnalytics('Login: Invalid Password', error);

return;
} else if (error === PASSCODE_NOT_SET_ERROR) {
Alert.alert(
'Security Alert',
Expand Down
5 changes: 4 additions & 1 deletion app/components/Views/Settings/SecuritySettings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
import CookieManager from '@react-native-community/cookies';
import Icon from 'react-native-vector-icons/FontAwesome';
import HintModal from '../../../UI/HintModal';
import { trackErrorAsAnalytics } from '../../../../util/analyticsV2';

const isIos = Device.isIos();

Expand Down Expand Up @@ -393,8 +394,10 @@ class Settings extends PureComponent {
} catch (e) {
if (e.message === 'Invalid password') {
Alert.alert(strings('app_settings.invalid_password'), strings('app_settings.invalid_password_message'));
trackErrorAsAnalytics('SecuritySettings: Invalid password', e?.message);
} else {
Logger.error(e, 'SecuritySettings:biometrics');
}
Logger.error(e, 'SecuritySettings:biometrics');
this.setState({ [type]: !enabled, loading: false });
}
};
Expand Down
Loading

0 comments on commit 68c9d6c

Please sign in to comment.