From cf74dc5c6cba343199b6336a792a552c0072611c Mon Sep 17 00:00:00 2001 From: LeoTM <1881059+leotm@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:49:33 +0100 Subject: [PATCH] fix: only remove SES from exception if exception exists (#9867) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Follow-up to - https://github.com/MetaMask/metamask-mobile/pull/8584 There's been a recent spike in errors throwing at https://github.com/MetaMask/metamask-mobile/blob/11ce2f3678039a73b20d5cc6e07782c5604ae24f/app/util/sentry/utils.js#L94-L95 This change ensures the error exists, before removing SES from the stack trace frame In a similar manner to how we've been doing it in https://github.com/MetaMask/metamask-mobile/blob/11ce2f3678039a73b20d5cc6e07782c5604ae24f/app/util/sentry/utils.js#L44-L51 This doesn't impact users and will help assess the underlying error causing the spike ## **Related issues** Fixes: https://github.com/MetaMask/metamask-mobile/issues/9221 ## **Manual testing steps** Same as: https://github.com/MetaMask/metamask-mobile/pull/8584 In below example, triggered by a button in: app/components/Views/OnboardingCarousel/index.js ## **Screenshots/Recordings** Screenshot 2024-06-06 at 4 27 36 PM ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- app/util/sentry/utils.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/util/sentry/utils.js b/app/util/sentry/utils.js index 34f31b4e3ce..e04ce7ac75a 100644 --- a/app/util/sentry/utils.js +++ b/app/util/sentry/utils.js @@ -92,11 +92,13 @@ function removeDeviceName(report) { * @param {*} report - the error event */ function removeSES(report) { - const stacktraceFrames = report.exception.values[0].stacktrace.frames; - const filteredFrames = stacktraceFrames.filter( - (frame) => frame.filename !== 'app:///ses.cjs', - ); - report.exception.values[0].stacktrace.frames = filteredFrames; + const stacktraceFrames = report?.exception?.values[0]?.stacktrace?.frames; + if (stacktraceFrames) { + const filteredFrames = stacktraceFrames.filter( + (frame) => frame.filename !== 'app:///ses.cjs', + ); + report.exception.values[0].stacktrace.frames = filteredFrames; + } } function rewriteReport(report) {