@@ -6,9 +6,7 @@ import { defaultPreferencesInstance } from 'compass-preferences-model';
66import semver from 'semver' ;
77import { CompassElectron } from './components/entrypoint' ;
88import { openToast , ToastBody } from '@mongodb-js/compass-components' ;
9-
10- import './index.less' ;
11- import 'source-code-pro/source-code-pro.css' ;
9+ import ensureError from 'ensure-error' ;
1210
1311import * as marky from 'marky' ;
1412import * as webvitals from 'web-vitals' ;
@@ -35,10 +33,9 @@ import { injectCSP } from './utils/csp';
3533const { log, mongoLogId } = createLogger ( 'COMPASS-APP' ) ;
3634const track = createIpcTrack ( ) ;
3735
38- /**
39- * Default version used when no version information is available
40- * or when initializing version-related functionality
41- */
36+ import './index.less' ;
37+ import 'source-code-pro/source-code-pro.css' ;
38+
4239const DEFAULT_APP_VERSION = '0.0.0' ;
4340
4441class Application {
@@ -77,6 +74,32 @@ class Application {
7774 } ;
7875 }
7976
77+ private setupGlobalErrorHandling ( ) {
78+ // Global Error Handling
79+ // Sets up error reporting to main process before any other initialization
80+ // Ensures all unhandled errors are properly logged and reported
81+ window . addEventListener ( 'error' , ( event : ErrorEvent ) => {
82+ event . preventDefault ( ) ;
83+ const error = ensureError ( event . error ) ;
84+ void ipcRenderer ?. call ( 'compass:error:fatal' , {
85+ message : error . message ,
86+ stack : error . stack ,
87+ } ) ;
88+ } ) ;
89+
90+ window . addEventListener (
91+ 'unhandledrejection' ,
92+ ( event : PromiseRejectionEvent ) => {
93+ event . preventDefault ( ) ;
94+ const error = ensureError ( event . reason ) ;
95+ void ipcRenderer ?. call ( 'compass:rejection:fatal' , {
96+ message : error . message ,
97+ stack : error . stack ,
98+ } ) ;
99+ }
100+ ) ;
101+ }
102+
80103 private setupWebVitals ( ) {
81104 function trackPerfEvent ( {
82105 name,
@@ -452,6 +475,10 @@ class Application {
452475 marky . mark ( 'Time to Connect rendered' ) ;
453476 marky . mark ( 'Time to user can Click Connect' ) ;
454477
478+ // Setup global error handling first to ensure all
479+ // unhandled errors are properly logged and reported
480+ this . setupGlobalErrorHandling ( ) ;
481+
455482 // Inject CSP first to prevent any CSP violations.
456483 injectCSP ( ) ;
457484
0 commit comments