Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #937 from cds-snc/feature/remove-console
Browse files Browse the repository at this point in the history
Remove direct access to `console` commands.
  • Loading branch information
jeberhardt authored Jul 28, 2020
2 parents 348d9e2 + e080aff commit 3359421
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 14 deletions.
9 changes: 5 additions & 4 deletions src/navigation/DevPersistedNavigationContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {InitialState, NavigationContainerRef, NavigationContainer} from '@react-
import AsyncStorage from '@react-native-community/async-storage';
import * as React from 'react';
import {InteractionManager} from 'react-native';
import {captureException} from 'shared/log';

interface DevPersistedNavigationContainerProps extends React.ComponentProps<typeof NavigationContainer> {
persistKey: string;
Expand All @@ -20,8 +21,8 @@ function DevPersistedNavigationContainerImpl(
persistInteractionRef.current = null;
try {
await AsyncStorage.setItem(persistKey, JSON.stringify(state));
} catch (ex) {
console.warn(`Failed to persist state. ${ex.message}`);
} catch (error) {
captureException(`Failed to persist state.`, error);
}
};

Expand All @@ -48,8 +49,8 @@ function DevPersistedNavigationContainerImpl(
setInitialState(JSON.parse(jsonString));
}
setIsReady(true);
} catch (ex) {
console.warn(`Failed to load state. ${ex.message}`);
} catch (error) {
captureException(`Failed to load state.`, error);
setIsReady(true);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/screens/home/views/ExposureView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useI18n} from 'locale';
import {Text, Box, ButtonSingleLine} from 'components';
import {useStorage} from 'services/StorageService';
import {useAccessibilityAutoFocus} from 'shared/useAccessibilityAutoFocus';
import {captureException} from 'shared/log';

import {BaseHomeView} from '../components/BaseHomeView';

Expand All @@ -27,7 +28,7 @@ export const ExposureView = ({isBottomSheetExpanded}: {isBottomSheetExpanded: bo
}, [i18n, region]);

const onActionGuidance = useCallback(() => {
Linking.openURL(getGuidanceURL()).catch(err => console.error('An error occurred', err));
Linking.openURL(getGuidanceURL()).catch(error => captureException('An error occurred', error));
}, [getGuidanceURL]);
const onHowToIsolate = useCallback(() => navigation.navigate('HowToIsolate'), [navigation]);
const autoFocusRef = useAccessibilityAutoFocus(!isBottomSheetExpanded);
Expand Down
3 changes: 2 additions & 1 deletion src/screens/home/views/FrameworkUnavailableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useI18n} from 'locale';
import {Box, ButtonSingleLine, Text, TextMultiline} from 'components';
import React, {useCallback} from 'react';
import {useAccessibilityAutoFocus} from 'shared/useAccessibilityAutoFocus';
import {captureException} from 'shared/log';
import {Linking} from 'react-native';

import {BaseHomeView} from '../components/BaseHomeView';
Expand All @@ -10,7 +11,7 @@ export const FrameworkUnavailableView = ({isBottomSheetExpanded}: {isBottomSheet
const i18n = useI18n();

const onHelp = useCallback(() => {
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(err => console.error('An error occurred', err));
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(error => captureException('An error occurred', error));
}, [i18n]);

const autoFocusRef = useAccessibilityAutoFocus(!isBottomSheetExpanded);
Expand Down
3 changes: 2 additions & 1 deletion src/screens/home/views/InfoShareView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {TouchableOpacity, TouchableOpacityProps, Linking} from 'react-native';
import {Box, Text, Icon, IconProps} from 'components';
import {useNavigation} from '@react-navigation/native';
import {useI18n} from 'locale';
import {captureException} from 'shared/log';

interface InfoShareItemProps extends TouchableOpacityProps {
onPress: () => void;
Expand Down Expand Up @@ -47,7 +48,7 @@ export const InfoShareView = () => {
const onLanguage = useCallback(() => navigation.navigate('LanguageSelect'), [navigation]);
const onRegion = useCallback(() => navigation.navigate('RegionSelect'), [navigation]);
const onHelp = useCallback(() => {
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(err => console.error('An error occurred', err));
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(error => captureException('An error occurred', error));
}, [i18n]);

return (
Expand Down
3 changes: 2 additions & 1 deletion src/screens/home/views/UnknownProblemView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {useI18n} from 'locale';
import {Box, ButtonSingleLine, Text} from 'components';
import React, {useCallback} from 'react';
import {useAccessibilityAutoFocus} from 'shared/useAccessibilityAutoFocus';
import {captureException} from 'shared/log';
import {Linking} from 'react-native';

import {BaseHomeView} from '../components/BaseHomeView';
Expand All @@ -10,7 +11,7 @@ export const UnknownProblemView = ({isBottomSheetExpanded}: {isBottomSheetExpand
const i18n = useI18n();

const onHelp = useCallback(() => {
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(err => console.error('An error occurred', err));
Linking.openURL(i18n.translate('Info.HelpUrl')).catch(error => captureException('An error occurred', error));
}, [i18n]);

const autoFocusRef = useAccessibilityAutoFocus(!isBottomSheetExpanded);
Expand Down
3 changes: 2 additions & 1 deletion src/screens/nocode/NoCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {BulletPoint} from 'components/BulletPoint';
import {BulletPointOrdered} from 'components/BulletPointOrdered';
import {SafeAreaView} from 'react-native-safe-area-context';
import {useAccessibilityAutoFocus} from 'shared/useAccessibilityAutoFocus';
import {captureException} from 'shared/log';

interface ContentProps {
title: string;
Expand All @@ -26,7 +27,7 @@ const Content = ({title, body, notCoveredList, coveredList, externalLinkText, ex
<ButtonSingleLine
variant="bigFlat"
text={externalLinkText}
onPress={() => Linking.openURL(externalLinkCTA).catch(err => console.error('An error occurred', err))}
onPress={() => Linking.openURL(externalLinkCTA).catch(error => captureException('An error occurred', error))}
externalLink
/>
) : null;
Expand Down
2 changes: 1 addition & 1 deletion src/services/BackendService/BackendService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class BackendService implements BackendInterface {
try {
randomBytes = await getRandomBytes(32);
} catch (error) {
console.error('getRandomBytes()', error);
captureException('getRandomBytes()', error);
throw new Error(error);
}
nacl.setPRNG(buff => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Schema, Validator, ValidatorResult} from 'jsonschema';
import {captureException} from 'shared/log';

import {ExposureConfiguration} from '../../bridge/ExposureNotification';

Expand All @@ -14,8 +15,7 @@ export class ExposureConfigurationValidator {
const validator = new Validator();
const validatorResult = validator.validate(exposureConfiguration, schema);
if (!validatorResult.valid) {
console.log('invalid json');
console.log(validatorResult.errors.toString());
captureException('invalid json', null);
throw new ExposureConfigurationValidationError(
`Invalid Exposure Configuration JSON. ${validatorResult.errors.toString()}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class ExposureNotificationService {
try {
await this.secureStorage.set(SUBMISSION_AUTH_KEYS, serialized, {});
} catch (error) {
console.error(error);
captureException('Unable to store SUBMISSION_AUTH_KEYS', error);
}
const cycleStartsAt = getCurrentDate();
this.exposureStatus.append({
Expand Down
7 changes: 7 additions & 0 deletions src/shared/log.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
export const captureMessage = async (message: string, params: {[key in string]: any} = {}) => {
// force return for production
return;

const finalMessage = message;
const finalParams = params;

if (!__DEV__) {
return;
}
console.log(finalMessage, finalParams);
};

export const captureException = async (message: string, error: any, params: {[key in string]: any} = {}) => {
// force return for production
return;

const finalMessage = `Error: ${message}`;
const finalParams = {
...params,
Expand Down
4 changes: 3 additions & 1 deletion src/shared/useReduceMotionPreference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {useEffect, useState} from 'react';
import {AccessibilityInfo, AccessibilityEvent} from 'react-native';

import {captureException} from './log';

export function useReduceMotionPreference() {
const [prefersReducedMotion, setPreference] = useState(false);
useEffect(() => {
Expand All @@ -10,7 +12,7 @@ export function useReduceMotionPreference() {
AccessibilityInfo.isReduceMotionEnabled()
.then(handleChange)
.catch(error => {
console.warn('AccessibilityInfo.isReduceMotionEnabled promise failed', error);
captureException('AccessibilityInfo.isReduceMotionEnabled promise failed', error);
});
AccessibilityInfo.addEventListener('reduceMotionChanged', handleChange);
return () => {
Expand Down

0 comments on commit 3359421

Please sign in to comment.