Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(INJI-560): add error events at multiple places #1012

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions components/PasscodeVerify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import {useTranslation} from 'react-i18next';
import {PinInput} from './PinInput';
import {hashData} from '../shared/commonUtil';
import {argon2iConfig} from '../shared/constants';
import {
getErrorEventData,
sendErrorEvent,
} from '../shared/telemetry/TelemetryUtils';
import {TelemetryConstants} from '../shared/telemetry/TelemetryConstants';

export const MAX_PIN = 6;

Expand Down Expand Up @@ -32,6 +37,13 @@ export const PasscodeVerify: React.FC<PasscodeVerifyProps> = props => {
}
}
} catch (error) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.appLogin,
TelemetryConstants.ErrorId.mismatch,
error,
),
);
console.log('error:', error);
}
}
Expand Down
52 changes: 52 additions & 0 deletions machines/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ export const storeMachine =
'Dummy',
);
} catch (e) {
sendErrorEvent(getErrorEventData('ENCRYPTION', '', e));

if (e.message.includes(keyinvalidatedString)) {
await clear();
callback(model.events.KEY_INVALIDATE_ERROR());
Expand All @@ -294,6 +296,13 @@ export const storeMachine =
}
callback(model.events.READY());
} else {
sendErrorEvent(
getErrorEventData(
'ENCRYPTION',
'',
'Could not get the android Key alias',
),
);
callback(
model.events.ERROR(
new Error('Could not get the android Key alias'),
Expand Down Expand Up @@ -400,6 +409,14 @@ export const storeMachine =
}
callback(model.events.STORE_RESPONSE(response, event.requester));
} catch (e) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
'',
e.message,
{e},
),
);
if (e.message.includes(keyinvalidatedString)) {
await clear();
callback(model.events.KEY_INVALIDATE_ERROR());
Expand Down Expand Up @@ -432,6 +449,13 @@ export const storeMachine =
console.log('Credentials successfully loaded for user');
callback(model.events.KEY_RECEIVED(existingCredentials.password));
} else {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
'',
'Could not get keychain credentials',
),
);
console.log('Credentials failed to load for user');
callback(
model.events.ERROR(
Expand All @@ -452,6 +476,13 @@ export const storeMachine =
if (hasSetCredentials) {
callback(model.events.KEY_RECEIVED(randomBytesString));
} else {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
'',
'Could not generate keychain credentials',
),
);
callback(
model.events.ERROR(
new Error('Could not generate keychain credentials.'),
Expand Down Expand Up @@ -532,6 +563,13 @@ export async function getItem(
}
if (data === null && VCMetadata.isVCKey(key)) {
await removeItem(key, data, encryptionKey);
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.tampered,
tamperedErrorMessageString,
),
);
throw new Error(tamperedErrorMessageString);
} else {
return defaultValue;
Expand All @@ -544,8 +582,22 @@ export async function getItem(
e instanceof BiometricCancellationError ||
e.message.includes('Key not found') // this error happens when previous get Item calls failed due to key invalidation and data and keys are deleted
) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.tampered,
e.message,
),
);
throw e;
}
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.tampered,
`Exception in getting item for ${key}: ${e}`,
),
);
console.error(`Exception in getting item for ${key}: ${e}`);
return defaultValue;
}
Expand Down
12 changes: 11 additions & 1 deletion screens/Home/MyVcs/AddVcModalMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,21 @@ export const AddVcModalMachine =
'OTP is invalid': 'invalidOtp',
'OTP has expired': 'expiredOtp',
};
return OTP_ERRORS_MAP[message]

const otpErrorMessage = OTP_ERRORS_MAP[message]
? i18n.t(`errors.backend.${OTP_ERRORS_MAP[message]}`, {
ns: 'AddVcModal',
})
: message;

sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.vcDownload,
message,
otpErrorMessage,
),
);
return otpErrorMessage;
},
}),

Expand Down
23 changes: 23 additions & 0 deletions shared/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
} from './constants';
import FileStorage, {getFilePath, vcDirectoryPath} from './fileStorage';
import {__AppId} from './GlobalVariables';
import {getErrorEventData, sendErrorEvent} from './telemetry/TelemetryUtils';
import {TelemetryConstants} from './telemetry/TelemetryConstants';

export const MMKV = new MMKVLoader().initialize();

Expand Down Expand Up @@ -80,6 +82,13 @@ class Storage {
const isCorrupted = await this.isCorruptedVC(key, encryptionKey, data);

if (isCorrupted) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.tampered,
'VC is corrupted and will be deleted from storage',
),
);
console.debug(
'[Inji-406]: VC is corrupted and will be deleted from storage',
);
Expand Down Expand Up @@ -110,9 +119,23 @@ class Storage {
);

if (isDownloaded && error.message.includes(ENOENT)) {
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.dataRetrieval,
error.message,
),
);
throw new Error(ENOENT);
}
}
sendErrorEvent(
getErrorEventData(
TelemetryConstants.FlowType.fetchData,
TelemetryConstants.ErrorId.dataRetrieval,
'Error Occurred while retriving from Storage',
),
);

console.log('Error Occurred while retriving from Storage.', error);
throw error;
Expand Down
3 changes: 3 additions & 0 deletions shared/telemetry/TelemetryConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const TelemetryConstants = {
appLogin: 'App Login',
vcLockOrRevoke: 'VC Lock / VC Revoke',
getVcUsingAid: 'Get VC using AID',
fetchData: 'Fetch Data',
}),

EndEventStatus: Object.freeze({
Expand Down Expand Up @@ -37,6 +38,8 @@ export const TelemetryConstants = {
userCancel: 'USER_CANCEL',
resend: 'RESEND',
activationFailed: 'ACTIVATION_FAILED',
tampered: 'TAMPERED',
dataRetrieval: 'DATA_RETRIEVAL',
}),

Screens: Object.freeze({
Expand Down