Skip to content

Commit

Permalink
Update error handling to avoid crashing
Browse files Browse the repository at this point in the history
We now capture unrecognized errors and report them to Sentry, rather
than throwing them. This ensures that any new failures would not brick
the wallet.
  • Loading branch information
Gudahtt committed Jul 18, 2024
1 parent 05d3384 commit 8341502
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/scripts/offscreen.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { captureException } from '@sentry/browser';
import { OffscreenCommunicationTarget } from '../../shared/constants/offscreen-communication';

/**
Expand Down Expand Up @@ -37,20 +38,22 @@ export async function createOffscreen() {
'Used for Hardware Wallet and Snaps scripts to communicate with the extension.',
});
} catch (error) {
if (offscreenDocumentLoadedListener) {
chrome.runtime.onMessage.removeListener(offscreenDocumentLoadedListener);
}
if (
error?.message?.startsWith(
'Only a single offscreen document may be created',
)
) {
console.debug('Offscreen document already exists; skipping creation');
if (offscreenDocumentLoadedListener) {
chrome.runtime.onMessage.removeListener(
offscreenDocumentLoadedListener,
);
}
return;
} else {
// Report unrecongized errors without halting wallet initialization
// Failures to create the offscreen document does not compromise wallet data integrity or
// core functionality, it's just needed for specific features.
captureException(error);
}
throw error;
return;
}

// In case we are in a bad state where the offscreen document is not loading, timeout and let execution continue.
Expand Down

0 comments on commit 8341502

Please sign in to comment.