Skip to content

Commit b8499ae

Browse files
committed
chore: added disclaimer
1 parent 2a149db commit b8499ae

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

packages/compass/src/app/application.tsx

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { defaultPreferencesInstance } from 'compass-preferences-model';
66
import semver from 'semver';
77
import { CompassElectron } from './components/entrypoint';
88
import { 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

1311
import * as marky from 'marky';
1412
import * as webvitals from 'web-vitals';
@@ -35,10 +33,9 @@ import { injectCSP } from './utils/csp';
3533
const { log, mongoLogId } = createLogger('COMPASS-APP');
3634
const 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+
4239
const DEFAULT_APP_VERSION = '0.0.0';
4340

4441
class 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

packages/compass/src/app/index.ts

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1+
/**
2+
* IMPORTANT:
3+
*
4+
* This file (index.ts) is not meant for regular application lifecycle logic.
5+
* It should ONLY contain code that:
6+
* 1. Must run before any other application code
7+
* 2. Sets up critical infrastructure that other modules depend on
8+
* 3. Handles global error boundaries and process-level configuration
9+
*
10+
* Examples of what belongs here:
11+
* - Stateful setup for core node modules (dns, EventEmitter)
12+
* - Process-level environment variables
13+
* - Any setup required by other modules (including 3rd party modules) before
14+
* they can be imported
15+
*
16+
* All other application lifecycle code, initialization, and business logic
17+
* should be placed in application.tsx instead.
18+
*
19+
* Rule of thumb: If the code isn't required for other modules to function
20+
* correctly during import, it probably belongs in application.tsx.
21+
*/
122
import { setupHadronDistribution } from '../setup-hadron-distribution';
223
import dns from 'dns';
3-
import ensureError from 'ensure-error';
4-
import { ipcRenderer } from 'hadron-ipc';
524
import EventEmitter from 'events';
625

26+
// Setup paths and environment variables for electron globals
727
setupHadronDistribution();
828

929
// DNS Configuration
@@ -17,30 +37,6 @@ if (!process.env.NODE_OPTIONS.includes('--dns-result-order')) {
1737
process.env.NODE_OPTIONS += ` --dns-result-order=ipv4first`;
1838
}
1939

20-
// Global Error Handling
21-
// Sets up error reporting to main process before any other initialization
22-
// Ensures all unhandled errors are properly logged and reported
23-
window.addEventListener('error', (event: ErrorEvent) => {
24-
event.preventDefault();
25-
const error = ensureError(event.error);
26-
void ipcRenderer?.call('compass:error:fatal', {
27-
message: error.message,
28-
stack: error.stack,
29-
});
30-
});
31-
32-
window.addEventListener(
33-
'unhandledrejection',
34-
(event: PromiseRejectionEvent) => {
35-
event.preventDefault();
36-
const error = ensureError(event.reason);
37-
void ipcRenderer?.call('compass:rejection:fatal', {
38-
message: error.message,
39-
stack: error.stack,
40-
});
41-
}
42-
);
43-
4440
// Event Emitter Configuration
4541
// Increases the default maximum number of listeners to prevent
4642
// potential memory leaks in development mode

0 commit comments

Comments
 (0)